Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx 1.2.0 - socket.io - HTTP/1.1 - Proxy websocket connections

Tags:

i would like to replace my node-http-proxy module with nginx proxy_pass module. Is it possible with new released nginx version, as i have read, that it supports HTTP/1.1 out of the box. I saw some threads struggeling with that problem, that websockets are not supported by nginx.

In my case im running several node projects in background and want to route my websocket connections from port 80 to 8000-8100, depending on domain. Is there a native way to do websocket proxy/reverse proxy without using the tcp_module addon?

I tried to setup an upstream in nginx.conf with proxy_passing to it, but if i try to connect to port 80 over websocket, i get an 502 Gateway error.

Anyone facing the same problem? Does anyone have a working example for nginx + spcket.io, proxying over port 80?

like image 997
ayk Avatar asked Apr 26 '12 07:04

ayk


1 Answers

No, this is not yet possible; nginx 1.2 incorporates stuff from the 1.1.x development branch which indeed includes HTTP/1.1 reverse proxying. Websocket connections are established using the HTTP/1.1 "Upgrade" header, but the fact that nginx now supports this kind of headers does not mean it supports websockets (websockets are a different protocol, not HTTP). (I tried this myself using the 1.1.x branch (which I found to be stable enough for my purpose) and it doesn't work without the tcp_module)

Websockets will probably be supported in 1.3.x ( http://trac.nginx.org/nginx/roadmap ).

Your alternatives are:

  • keep using node-http-proxy
  • use nginx without tcp module; socket.io won't use websockets but something else (e.g. long polling)
  • nginx with tcp module: in this case I think you need an additional port for this module (never tried this myself)
  • put something else in front as a reverse proxy: I use HAProxy (which supports websockets) in front of nginx and node. Nginx now simply acts as a static fileserver, not a proxy. Varnish is another option, if you want additional caching.
like image 190
Matthias Avatar answered Sep 19 '22 22:09

Matthias