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.

1 thought on “How to allow nginx to reverse proxy socket.io connections”

  1. i have a communication between two nodes and i have two locations

    node1 VM_Link:3000 & node2 VM_Link:3001

    server name : Domain.com

    location/chat {listen to VM_Link:3000}
    location/back {listen to VM_Link:3001}

    the problem is when i use the first node it calls automaticly the second node and when i use the server and write domain.com/chat it calls in the background automaticly domain.com:3001 and not domain.com/back

    WHAT SHOULD I DO ????

    Reply

Leave a Reply to Oussema MzoughiCancel reply