码农之家 - Websocket
type: channel
link: http://blog.liyx.fun/index.php/tag/Websocket/
items: Nginx支持Websocket反向代理

Nginx支持Websocket反向代理
type: item
date: 2020-10-16T16:09:00+08:00
description: Nginx支持Websocket反向代理1）编辑nginx.conf，在http区域内一定要添加下面配置：map $http_upgrade $connection_upgrade { default upgrade; '' close; } 2）编辑vhosts下虚拟主机的配置文件，在location匹配配置中添加如下内容：proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; 示例如下：http { map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { location / { root html; index index.html index.htm; proxy_pass http://webscoket; proxy_http_version 1.1; proxy_connect_timeout 4s; #配置点1 proxy_read_timeout 60s; #配置点2，如果没效，可以考虑这个时间配置长一点 proxy_send_timeout 12s; #配置点3 proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } } } 参考：https://www.cnblogs.com/kevingrace/p/9512287.html