简体   繁体   English

Kubernetes nginx ingress代理传递给websocket

[英]Kubernetes nginx ingress proxy pass to websocket

We are running rails application with unicorn and websocket. 我们正在使用独角兽和websocket运行rails应用程序。 We are using AWS ELB as ingress SSL terminates on ELB and forwards traffic to application. 我们正在使用AWS ELB,因为入口SSL终止于ELB并将流量转发到应用程序。

Nginx ingress routes traffic to web app running unicorn/puma on port 8080. Nginx ingress将流量路由到端口8080上运行unicorn / puma的web应用程序。

App works but our websocket responds with 200 instead of 101. We have enabled CORS and used required annotations in ingress. 应用程序工作,但我们的websocket响应200而不是101.我们已启用CORS并在入口中使用所需的注释。

This are annotations used for the ingress controller service 这是用于入口控制器服务的注释

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

When we use aws loadbalancer protocol as tcp and load balancer ports as 443 it fails on infinite redirect loop. 当我们使用aws loadbalancer协议作为tcp并将负载均衡器端口作为443时,它在无限重定向循环上失败。

Following are the annotations used in the ingress: 以下是入口中使用的注释:

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"

Our sample nginx configuration we used earlier without ingress is here 我们之前使用的没有入口的示例nginx配置就在这里

How to get websockets working with nginx ingress controller with AWS ELB ? 如何让websockets与AWS ELB一起使用nginx入口控制器?

Is it possible to try without CORS? 没有CORS可以尝试吗?

Part of the handshake is the client must send at least these headers: 握手的一部分是客户端必须至少发送以下这些标头:

Sec-WebSocket-Key
Sec-WebSocket-Version

And maybe something else. 也许别的东西。 Look at https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#The_WebSocket_Handshake 请查看https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#The_WebSocket_Handshake

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM