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

前端 未结 2 1102
抹茶落季
抹茶落季 2021-01-30 17:52

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

相关标签:
2条回答
  • 2021-01-30 18:16

    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.
    0 讨论(0)
  • 2021-01-30 18:20

    In relation to NginX with TCP module there are few problems I have encountered. But the most tricky one is trying to run your websockets with nginx on port 80 on EC2 instance.

    I described whole configuration here

    0 讨论(0)
提交回复
热议问题