title: Could not connect websocket using Action Cable
body: <p>Could not connect websocket using Action Cable in Rails 5.1. HTTP server is Unicorn on nginx and adapter is Redis.</p>
  
  <p>Rails configuration is the following.</p>
  
  <pre><code># config/environments/production.rb
  config.action_cable.disable_request_forgery_protection = true
  </code></pre>
  
  <p>nginx configuration is the following.</p>
  
  <pre><code>upstream unicorn {
    server unix:/rails/current/tmp/sockets/unicorn.sock;
  }
  
  server {
    listen 80;
    charset utf-8;
    server_name sub.example.com;
    root /rails/current/public;
  
    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
  
      if (!-f $request_filename) {
        proxy_pass http://unicorn;
        break;
      }
    }
    location /cable {
      proxy_pass http://unicorn;
      proxy_http_version 1.1;
      proxy_set_header Upgrade "websocket";
      proxy_set_header Connection "Upgrade";
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_redirect off;
    }
    ...
  }
  </code></pre>
  
  <p>Errors in console of web browser are the following.</p>
  
  <pre><code>WebSocket connection to 'wss://sub.example.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404
  </code></pre>
  
  <p>Errors in Rails are the following.</p>
  
  <pre><code>[ERROR] Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: close, HTTP_UPGRADE: )
  [INFO] Finished "/cable/"[non-WebSocket] for xxx.xxx.xxx.xxx at 2017-xx-xx
  </code></pre>
  
  <p><strong>A strangest thing is a error in Rails does not have <code>HTTP_UPGRADE</code> value</strong>. But HTTP request headers of web browser include <code>Upgrade</code> key and <code>websocket</code> value. Also setting <code>"websocket"</code> for proxy header in nginx configurations.</p>
  
  <p>What should I do?</p>