带有NGINX和Rails ActionCable的Websockets

csi*_*csi 5 nginx amazon-web-services websocket actioncable

我们的配置有什么问题?NGINX没有添加正确的标头.

使用React前端wss通过AWS ELB接收的连接初始化客户端,未加密传递给nginx,proxy_passed传递给Rails后端.

反应连接网址
wss://mydomain.com/ws/cable

nginx配置
location /ws/ { proxy_pass ?http://backend_host/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 86400; }

在Rails中,ws 在这里失败,因为env['HTTP_CONNECTION']env['HTTP_UPGRADE']没有被nginx正确设置.

env['HTTP_CONNECTION']应该等于"升级"而是"关闭"
env['HTTP_UPGRADE']应该等于"websocket"而是nil

我们可以在nginx中修改哪些内容来修复这些标头?