title: Websockets with NGINX and Rails ActionCable
body: <p>What is wrong with our configuration?  NGINX is not adding the proper headers.  </p>
  
  <p>Using React front end to initialize client with <code>wss</code> connection, received by AWS ELB, passed unencrypted to nginx, proxy_passed to Rails backend.</p>
  
  <p>React connection url<br>
  <code>wss://mydomain.com/ws/cable</code></p>
  
  <p>nginx config<br>
  <code>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;
  }
  </code></p>
  
  <p>In Rails, the ws fails <a href="https://github.com/faye/websocket-driver-ruby/blob/b14488aac51b7e3be726c74ecc7fcd8cb14819e3/lib/websocket/driver.rb#L223-L230" rel="noreferrer">here</a> because <code>env['HTTP_CONNECTION']</code> and <code>env['HTTP_UPGRADE']</code> are not correctly set by nginx.</p>
  
  <p><code>env['HTTP_CONNECTION']</code> should equal "Upgrade" and instead is "close"<br>
  <code>env['HTTP_UPGRADE']</code> should equal "websocket" and instead is nil  </p>
  
  <p>What can we change in nginx to fix these headers?</p>