解决办法:在 Nginx ,location 中添加以下代码:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
完整的nginx配置信息如下:
server {
listen 80;
server_name localhost;
#my java server config
location /website/ {
add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://127.0.0.1:8848/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}