Can nginx be used as a reverse proxy for a backend websocket server?

前端 未结 7 2506
甜味超标
甜味超标 2020-11-30 19:51

We\'re working on a Ruby on Rails app that needs to take advantage of html5 websockets. At the moment, we have two separate \"servers\" so to speak: our main app running on

7条回答
  •  执笔经年
    2020-11-30 19:54

    Out of the box (i.e. official sources) Nginx can establish only HTTP 1.0 connections to an upstream (=backend), which means no keepalive is possibe: Nginx will select an upstream server, open connection to it, proxy, cache (if you want) and close the connection. That's it.

    This is the fundamental reason frameworks requiring persistent connections to the backend would not work through Nginx (no HTTP/1.1 = no keepalive and no websockets I guess). Despite having this disadvantage there is an evident benefit: Nginx can choose out of several upstreams (load balance) and failover to alive one in case some of them failed.

    Edit: Nginx supports HTTP 1.1 to backends & keepalive since version 1.1.4. "fastcgi" and "proxy" upstreams are supported. Here it is the docs

提交回复
热议问题