title: Socket.io/WebSockets continuously reconnecting — issue with Nginx proxy configuration?
body: <p>I am using Socket.IO in my Node.js application. Today I deployed it for the first time, and I noticed that my sockets keep reconnecting. I have "connect" and "disconnect" logging to the console in the respective socket events, and this is the result:</p>
  
  <p><img src="https://cl.ly/image/1W1j2b0p1q1J/content" alt=""></p>
  
  <p>What's more, it seems that the polling technique is being used, when my browser is surely modern enough to use WebSockets — so I believe this is a configuration issue. WebSockets work fine when I am running the Node.js in development with no proxy in the middle.</p>
  
  <p>This is my Nginx configuration, which serves as a proxy to my Node.js server:</p>
  
  <pre><code>upstream reader.oliverjash.me {
    server 127.0.0.1:3000;
  }
  
  server {
    listen 80;
    server_name reader.oliverjash.me;
    access_log /var/log/nginx/reader.oliverjash.me.access.log;
    error_log /var/log/nginx/reader.oliverjash.me.error.log;
  
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
  
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
  
      proxy_pass http://reader.oliverjash.me;
      proxy_redirect off;
    }
  }
  </code></pre>
  
  <p>I believe that the lines:</p>
  
  <pre><code>proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  </code></pre>
  
  <p>are significant in enabling WebSockets (as per <a href="https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/" rel="nofollow noreferrer">this reference/tutorial</a>). Before I added these, WebSockets did not work at all with the proxy. Now I seem to get polling, which is better than nothing.</p>
  
  <p>My Nginx version is 1.4.0 stable.</p>