amazon-web-services - Kubernetes nginx 入口代理传递给 websocket

标签 amazon-web-services nginx websocket kubernetes docker-ingress

我们正在使用 unicorn 和 websocket 运行 Rails 应用程序。 我们使用 AWS ELB 作为入口 SSL 在 ELB 上终止并将流量转发到应用程序。

Nginx 入口将流量路由到在端口 8080 上运行 unicorn/puma 的网络应用。

应用程序运行正常,但我们的 websocket 响应为 200 而不是 101。我们启用了 CORS 并在入口中使用了必需的注释。

这是用于入口 Controller 服务的注解

service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
service.beta.kubernetes.io/aws-load-balancer-ssl-cert::arn:aws:iam::xxx:server-certificate/staging
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https

当我们将 aws loadbalancer 协议(protocol)用作 tcp 并将负载平衡器端口用作 443 时,它会在无限重定向循环中失败。

以下是入口中使用的注解:

nginx.ingress.kubernetes.io/service-upstream: true      
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
ingress.kubernetes.io/force-ssl-redirect: "true"

我们之前使用的没有入口的示例 nginx 配置是 here

如何让 websockets 与带有 AWS ELB 的 nginx 入口 Controller 一起工作?

最佳答案

是否可以在没有 CORS 的情况下尝试?

握手的一部分是客户端必须至少发送这些 header :

Sec-WebSocket-Key
Sec-WebSocket-Version

也许还有别的。看https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#The_WebSocket_Handshake

关于amazon-web-services - Kubernetes nginx 入口代理传递给 websocket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48057506/

相关文章:

amazon-web-services - 如何设置 AWS ELB 阻止来自给定 IP 的过多查询?

amazon-web-services - 使用多个条件表达式的 AWS DynamoDB 更新项目

django - 如何通过 uwsgi 强制应用程序的标准输出日志?

php - 如何在 php 站点上的专用 Node.js 服务器上使用 Socket.io?

javascript - 如何在 node.js 中获取字符串的 sha1 哈希?

browser - 如何禁用 WS/WSS 协议(protocol)浏览器

amazon-web-services - Docker Swarm关于AWS Cloudformation的说明

mysql - 无法从 Rails 更新 RDS 数据库

nginx - 无法从 Nginx php - 基于 fpm 的 dedi 发送电子邮件?

nginx - nginx 用户指令的含义