关键一:vue配置
'/ws': {
target: process.env.BASE_URL,
changeOrigin: true, //开启代理
ws: true, // 是否启用websockets
pathRewrite: {
'^/ws': ''
}
}
关键二:nginx配置
#nginx配置websocket
location /ws {
proxy_pass http://localhost:8881/ws/; #websocket地址
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
配置完成后重启再测试!