只能使用nginx代理转发
client:
// 创建socket连接,使用wss协议
const socket = io('wss://www.xxx.world', {
reconnectionAttempts: 10,
query: {
uid: this.state.user.uid
}
})
nginx:
// 在server模块下加入一个location配置,代理地址使用ip加端口号
location /socket.io/ {
proxy_pass http://68.168.128.247:7001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
}