Https 使用 wss 配置
前几天做 GatewayWorker
做 Socket 通信,本地开发测试时使用的是 ws
连接,到了线上因为使用了 https
导致通信连接不上,端口都是正常监听。
wss
连接是不允许使用端口号的,比如: socket.test:6001
,只能写固定的路由地址,所以我直接选择用 Nginx
转发到了 ws
端口
NGINX 配置
location /wss {
proxy_pass http://127.0.0.1:6001; // 转发到本地的 GATEWAYWORKER 注册的监听端口
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;
}
这样前端就可以直接发起 wss
连接了
ws = new Websocket('my.test/wss');
本作品采用《CC 协议》,转载必须注明作者和本文链接