Nginx做负载均衡之后,WebSocket无法直接连接到服务器,需要进行一些额外的配置
nginx.conf配置:
http节点下:
#websocket配置map $http_upgrade $connection_upgrade {default upgrade;'' close;}
server {listen 80;server_name www.easyboot.xyz;location / {proxy_pass http://localhost:8080;#配置Nginx支持webSocket开始proxy_set_header Host $http_host;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}
注意上述的「map」与「server」节点平级
