Reputation: 11
When I try to establish connection from browser to my api. I got an error in browser **[Error] WebSocket connection to 'wss://myhost.com/socket.io/?EIO=4&transport=websocket' failed: There was a bad response from the server.**
Also in ingress logs I found the next errors:
**[error] 2509#2509: *20476405 upstream prematurely closed connection while reading response header from upstream, client: 169.150.247.39, server: myhost.com, request: "GET /socket.io/?EIO=4&transport=websocket HTTP/1.1", upstream: "http://my-ip:4000/socket.io/?EIO=4&transport=websocket", host: "myhost.com"**
I'm using AWS EKS, + for Load Balancer type is classic. With long poling it was ok, but I want to connect with websockets only. I have the following Ingress configuration.
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-ingress-ingress-nginx-controller
namespace: default
data:
use-proxy-protocol: "true"
use-forwarded-headers: "true"
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-be
namespace: default
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/ssl-passthrough: 'true'
nginx.ingress.kubernetes.io/backend-protocol: 'HTTPS'
nginx.ingress.kubernetes.io/enable-websocket: "true"
nginx.org/websocket-services: backend
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($http_x_real_ip) {
set $real_ip $http_x_real_ip;
}
proxy_set_header X-Real-IP $real_ip;
nginx.ingress.kubernetes.io/server-snippet: |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
spec:
ingressClassName: nginx
tls:
- hosts:
- myhost.com
secretName: secret-tls
rules:
- host: myhost.com
http:
paths:
- path: /api/(.*)
pathType: ImplementationSpecific
backend:
service:
name: backend
port:
number: 4000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-socket-io
namespace: default
annotations:
nginx.ingress.kubernetes.io/ssl-passthrough: 'true'
nginx.org/websocket-services: backend
nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'
nginx.ingress.kubernetes.io/enable-websocket: "true"
nginx.ingress.kubernetes.io/server-snippet: |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
spec:
ingressClassName: nginx
tls:
- hosts:
- myhost.com
secretName: secret-tls
rules:
- host: myhost.com
http:
paths:
- path: /socket.io/
pathType: ImplementationSpecific
backend:
service:
name: backend
port:
number: 4000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-fe
namespace: default
annotations:
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: ingress-basic-auth
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
ingressClassName: nginx
tls:
- hosts:
- myhost.com
secretName: secret-tls
rules:
- host: myhost.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 3000
I tried to add timeouts and nginx.org/websocket-services: backend
but it didn't work as well
Upvotes: 0
Views: 23