I'm using Express.js to create a server to which I can connect using web sockets.
Even though it eventually seems to work (that, is connects and passes an event to the client), I initially get an error in Chrome's console:
Unexpected response code: 502
On the backend, the socket.io only logs warn - websocket connection invalid
.
However, nginx logs this:
2012/02/12 23:30:03 [error] 25061#0: *81 upstream prematurely closed connection while reading response header from upstream, client: 71.122.117.15, server: www.example.com, request: "GET /socket.io/1/websocket/1378920683898138448 HTTP/1.1", upstream: "http://127.0.0.1:8090/socket.io/1/websocket/1378920683898138448", host: "www.example.com"
Note: I have nginx dev running: nginx version: nginx/1.1.14
so it should support HTTP/1.1.
Also note that if I just use the node.js server without the nginx it works without any warnings.
Finally, here is my nginx config file:
server {
listen 0.0.0.0:80;
server_name www.example.com;
access_log /var/log/nginx/example.com.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_pass http://node;
proxy_redirect off;
}
}
upstream node {
server 127.0.0.1:8090;
}
Any help would be greatly appreciated. I tried the fix suggested in this question but that didn't work either.