I try to proxy node.js, socket.io and xhr-polling traffic through nginx.
Then Socket.io doesn't fire "disconnect" event.
However, bellow condition works fine.
- Direct connection to Node.js port without nginx proxy.
- Switch transport to websocket from xhr-polling.
My version is bellow.
- nginx : 1.4.4
- node.js : 0.10.24
- socket.io : 0.9.15
My nginx config file setting is below.
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
}
How can I fix this? Am I missing something? Thanks in Advance :)
In addition, I found new conditions that occurs my problem.
The result of my problem was depend on below.
- the client browser and mobile device.
- proxy throgh nginx (port 80) or direct access to node.js (port 3000).
The findings are following.
・ Chrome @ Mac OS X
・ Aquos Phone(Android Brower, Android 4.0.4)
port 80 ⇒ NG
port 3000 ⇒ OK
・ Gallaxy S(Android Brower, Android 4.2.2)
・ iPhone 5(Safari, iOS 7)
port 80 ⇒ NG
port 3000 ⇒ NG
- "OK" is "can fire disconnect event in realtime", "NG" is "can't fire disconnect event".
- "port 80" uses nginx, "port 3000" uses node.js.
- Trasport is xhr-polling only.
- Gallaxy S and iPhone 5 are compatible with websocket.