title: nginx and proxying WebSockets
body: <p>I'm trying to proxy WebSocket + HTTP traffic with nginx.</p>
  
  <p>I have read this: <a href="http://nginx.org/en/docs/http/websocket.html">http://nginx.org/en/docs/http/websocket.html</a></p>
  
  <p>My config looks like:</p>
  
  <pre><code>http {
      include       mime.types;
      default_type  application/octet-stream;
  
      sendfile        on;
      keepalive_timeout  65;
  
      gzip  on;
  
      map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
      }
  
      server {
        listen 80;
        server_name ourapp.com;
  
        location / {
          proxy_pass http://127.0.0.1:100;
          proxy_http_version 1.1;
          proxy_redirect off;
          proxy_set_header   Host             $host;
          proxy_set_header   X-Real-IP        $remote_addr;
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header   Upgrade          $http_upgrade;
          proxy_set_header   Connection       $connection_upgrade;
        }
      }
  }
  </code></pre>
  
  <p>I have 2 problems:</p>
  
  <p>1) The connection closes once a minute.</p>
  
  <p>2) I want to run both HTTP and WS on the same port. The application works fine locally, but if I try to put HTTP and WS on the same port and set this nginx proxy, I get this:</p>
  
  <blockquote>
    <p>WebSocket connection to 'ws://ourapp.com/ws' failed: Unexpected response code: 200 </p>
  </blockquote>
  
  <p>Loading the app (HTTP) seems to work fine, but WebSocket connection fails.</p>