如何在 nginx 后面的 AWS EKS 上部署 SignalR 服务器以允许 websocket 协议连接?

如何在 nginx 后面的 AWS EKS 上部署 SignalR 服务器以允许 websocket 协议连接?

我有一个带有 SignalR 的 .NET 6 Web API。直接连接到 API 时一切都运行正常 - 本地以及通过 AWS EKS 上的 Endpoint IP:Port。但是,当我尝试通过 NGINX 入口 URL ( http://some.url.com) 访问它时,它无法通过 websocket 传输方法进行连接。我收到以下错误:

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.

初始 websocket 尝试失败后,后备传输(服务器发送事件)起作用,但我理想情况下希望通过 websocket 连接。

我尝试过启用粘性会话,但似乎没有什么效果,以及https://stackoverflow.com/questions/48300288/signalr-in-asp-net-core-behind-nginx- 我遇到了完全相同的错误。

我的 Ingress 如下所示:

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

相关内容