I have a .NET 6 Web API with SignalR. Everything works perfectly when connecting directly to the API - locally as well as via Endpoint IP:Port on AWS EKS. However, it's failing to connect specifically via the websocket transport method when I try to access it via the NGINX ingress URL (http://some.url.com
). I get the following error:
Error: Failed to start the transport 'WebSockets': Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
The fallback transports (Server Sent Events) work after the initial websocket try fails but I ideally want to connect via websocket.
I've tried enabling sticky sessions but that doesn't seem to make a difference, as well as suggestions from https://stackoverflow.com/questions/48300288/signalr-in-asp-net-core-behind-nginx - I get the exact same error.
This is what my Ingress looks like:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-wsapp
namespace: dev
annotations:
nginx.ingress.kubernetes.io/affinity: cookie
nginx.ingress.kubernetes.io/read-timeout: '3600'
nginx.ingress.kubernetes.io/send-timeout: '3600'
nginx.ingress.kubernetes.io/configuration-snippet: |
server {
server_name some.url.com;
location / {
proxy_pass http://localhost:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
namespace: dev
labels:
app: wsapp
spec:
rules:
- host: some.url.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wsapp
port:
number: 8080