How to allow nginx to reverse proxy socket.io connections

We have just been setting up nginx as a reverse proxy for a node server. Everything worked fine except the socket.io connections weren’t making it through.

You make a reverse proxy with:

location / {
    proxy_pass http://localhost:1025/;
}

However to make nginx (version 1.3.13 +) reverse proxy socket.io you should add change your configuration to:

location / {
    proxy_pass http://localhost:1025/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
}

I learnt this from Chris Lea’s blog which is excellent. Also thank you Chris Lea for your excellent ppa’s.