I have a Problem with redirection WebSocket

Viewed 93

I have a problem, my reverse nginx proxy, which is located in the Kubernetes cluster, does not proxy the websocket, perhaps the problem is in the ingress that stands at the entrance to the cluster and redirects to nginx. I tried to add the necessary headers to the location, but the client still cannot receive a response from the server. If you use a nodeport, then the client receives a response from the server, when using nginx redirection, but receives a response.

default.conf:

server 
{  
listen *:80 ;
server_name MYDOMAIN.NAME;
location / {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_connect_timeout  3600s;
    proxy_read_timeout  3600s;
    proxy_send_timeout  3600s;
    send_timeout  3600s;


    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_set_header Upgrade websocket;     
    proxy_set_header Connection "upgrade";
    proxy_pass http://messenger:8082/;

    }
}

With this config, nginx gives the following error:

2021/10/18 16:45:00 [error] 22#22: *3 upstream timed out (110: Connection timed out) while reading upstream, client: xxx.xxx.x.xxx, server: MYDOMAIN.NAME, request: "GET /?event=77be3755-d31c-4a21-b21d-ff011e3a0977 HTTP/1.1", upstream: "http://messenger service ip/?event=77be3755-d31c-4a21-b21d-ff011e3a0977", host: MYDOMAIN.NAME
192.168.2.125 - - [18/Oct/2021:16:45:00 +0000] "GET /?event=77be3755-d31c-4a21-b21d-ff011e3a0977 HTTP/1.1" 101 0 "-" "SwiftWebSocket"

my ingress config:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
  nginx.org/websocket-services: "messenger"
spec:
  ingressClassName: nginx
  rules:
  - host: "my-inginx-domain"
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80

I still have several services and they work fine, but the messenger with the weightocket cannot, I tried to take information from the documentation, but it gives an error 400 and asked to add the websocket header, after which the above mentioned problem appears. I’m glad any thought suggested)

0 Answers
Related