title: "Cannot GET" on reverse proxy from Nginx to socket.io on express.js
body: <p>I've followed <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04?utm_source=Customerio&amp;utm_medium=Email_Internal&amp;utm_campaign=Email_nodeWelcome" rel="noreferrer">this tutorial</a> to get Node.js working through Nginx on a two Ubuntu 14.04 servers via private networking (Node.js is on myappserver - accessible via private IP myprivatewebserver and publicly via mypublicappserver -  and Nginx on mywebserver). Everything works fine til this point - I can access a node.js application on myprivateappserver:3000 proxied via Nginx by going to <a href="http://mywebserver/node" rel="noreferrer">http://mywebserver/node</a>.</p>
  
  <p>However, when I try and run up the <a href="http://socket.io/get-started/chat/" rel="noreferrer">chat application</a> in socket.io on express.js, it works when I access it directly (<a href="http://mypublicappserver:3000" rel="noreferrer">http://mypublicappserver:3000</a>) but, when I try and access it via my Nginx proxy (<a href="http://mywebserver/node" rel="noreferrer">http://mywebserver/node</a>), I get "Cannot GET /node" in the browser and in the firebug console "
  "NetworkError: 404 Not Found - <a href="http://mywebserver/node" rel="noreferrer">http://mywebserver/node</a>". </p>
  
  <p>If I curl <a href="http://myprivateappserver:3000" rel="noreferrer">http://myprivateappserver:3000</a> from mywebserver, I get index.html from my socket.io application fine. </p>
  
  <p>My /etc/nginx/sites-available/default contains:</p>
  
  <pre><code>location /node{
  proxy_pass http://myprivateappserver:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
  }
  </code></pre>
  
  <p>My index.js is:</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
  });
  
  io.on('connection', function(socket){
    console.log('a user connected');
    socket.on('disconnect', function(){
      console.log('user disconnected');
    });
    socket.on('chat message', function(msg){
      io.emit('chat message', msg);
    });
  });
  
  http.listen(3000, function(){
    console.log('listening on *:3000');
  });
  </code></pre>
  
  <p>and my index.html is:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Socket.IO chat&lt;/title&gt;
      &lt;style&gt;
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font: 13px Helvetica, Arial; }
        form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
        form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
        form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
        #messages { list-style-type: none; margin: 0; padding: 0; }
        #messages li { padding: 5px 10px; }
        #messages li:nth-child(odd) { background: #eee; }
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;ul id="messages"&gt;&lt;/ul&gt;
      &lt;form action=""&gt;
        &lt;input id="m" autocomplete="off" /&gt;&lt;button&gt;Send&lt;/button&gt;
      &lt;/form&gt;
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/jquery-1.11.1.js"&gt;&lt;/script&gt;
      &lt;script&gt;
        var socket = io();
        $('form').submit(function(){
          socket.emit('chat message', $('#m').val());
          $('#m').val('');
          return false;
        });
        socket.on('chat message', function(msg){
          $('#messages').append($('&lt;li&gt;').text(msg));
        });
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my first foray into nginx/node/express/socket (I'm normally an Apache/CakePHP person) so I may well be missing something very simple but would also be very grateful for any pointers on how to debug what's going wrong</p>