vue 3333 websocket-server 13334 正常联通,
当开启了nginx反向代理13334端口。使用postman测试代理获取数据失败
当关闭,并且前端提示跨域访问错误
XMLHttpRequest cannot load http://127.0.0.1:13334/socket.io/?EIO=3&transport=polling&t=LwvJyYo. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3333' is therefore not allowed access. The response had HTTP status code 404.
当关闭websocket-server ,postman测试获取正常
或者关闭nginx,vue前端连接websocket-server恢复正常,
这里问题来了,明显是ws-server和nginx有冲突,之所以要ws-server和nginx同时监听一个端口,目的是ws-server有一个ajax请求需要跨域通过
nginx转发
nginx简单配置如下
server {
listen 13334;
server_name localhost;
location = /end {
proxy_pass http://127.0.0.1:4000;
proxy_redirect default;
}
}
找到原因,nginx代理websocket需要ugrade,不可以单纯的http