【socket.io跨域】关于socket.io nginx跨域问题
程序员文章站
2022-05-31 17:31:39
...
服务端: node.js
前端环境: uni-app
需要依赖: vue-socket.io socket.io-client
// main.js
import VueSocketio from 'vue-socket.io'
import socketio from 'socket.io-client';
Vue.use(new VueSocketio({
debug: true,
connection: socketio('http://真实线上地址:3300')
}))
nginx配置 nginx.conf
server {
location /socket.io/ {
proxy_pass http://127.0.0.1:3300/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
}
}
原因: 会自动添加/socket.io前缀