Nginx 配置 WebSocket 转发;支持 ws 和 http请求;亲测有效~
http {
...
# 自定义变量 $connection_upgrade
map $http_upgrade $connection_upgrade {
default keep-alive; #默认为keep-alive 可以支持 一般http请求
'websocket' upgrade; #如果为websocket 则为 upgrade 可升级的。
}
server {
...
location /websocket/ {
proxy_pass http://127.0.0.1/websocket/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
proxy_set_header Connection $connection_upgrade;
}
}
}
注:以上内容仅提供参考和交流,请勿用于商业用途,如有侵权联系本人删除!



