6

What is wrong with our configuration? NGINX is not adding the proper headers.

Using React front end to initialize client with wss connection, received by AWS ELB, passed unencrypted to nginx, proxy_passed to Rails backend.

React connection url
wss://mydomain.com/ws/cable

nginx config
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; }

In Rails, the ws fails here because env['HTTP_CONNECTION'] and env['HTTP_UPGRADE'] are not correctly set by nginx.

env['HTTP_CONNECTION'] should equal "Upgrade" and instead is "close"
env['HTTP_UPGRADE'] should equal "websocket" and instead is nil

What can we change in nginx to fix these headers?

csi
  • 9,018
  • 8
  • 61
  • 81
  • Try removing the http:// before backend_host, so you just have `proxy_pass backend_host`. – Ryan Z Jul 24 '18 at 01:59
  • ELB basically does not support Websockets with HTTP/HTTPS listeners. Consider moving to TCP listeners with proxy protocol support or migrate to ALB ("ELBv2"), which is officially able to handle WS connections. – Joe Eig Jul 28 '18 at 13:28
  • Did you check this ?? https://stackoverflow.com/questions/18450310/nginx-add-header-not-working – Neeraj Kumar Jul 30 '18 at 11:24

0 Answers0