官网链接:
http://nginx.org/en/docs/http/websocket.html
location /chat/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
不过实际过程遇到最实际的问题是,websocket连接超时问题,ngxin默认是60s,可以通过
proxy_read_timeout属性来增强,这个属性就是设置websocket连接的超时时间
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout
不过,这个值不应该设置的过大,我觉得比较好的方法是通过客户端心跳来解决