问题:在阿里云部署后访问报错 404
解决方案:
jsp中创建websocket
var wsUrl ="ws://" + window.location.host + "/default/webSocket;
var ws = new WebSocket(wsUrl);
nginx.conf文件有两种配置方式
1.无upstream方式(简单模式)
server { } 中添加
location /default {
# 服务器ip+端口(ip可用命令ipconfig查看)
proxy_pass http://ip:端口号;
# 增加Upgrade协议头和Connection协议头,使http连接升级到websocket连接
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
}
2.使用upstream方式
http { } 中添加
upstream my-server {
server ip:端口号;
}server { } 中添加
location /default {
proxy_pass http://my-server;
# 增加Upgrade协议头和Connection协议头,使http连接升级到websocket连接
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
}