-
问题
今天在配置完https过后原有的ws不能使用了,需要升级为wss
-
配置
websocket服务端口为8898
-
解决
在tengine配置中443端口的server中加上配置
location /socket/ {
proxy_pass http://yourdomain:8898/socket/;
proxy_read_timeout 60s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
}
这里是对/socket请求转发到8898端口的websocket服务,加上Upgrade即可。
- 前端
var socket = io('https://yourdomain?token=' + token, {
path: '/socket'
});
这里https也能换成wss
- 拓展
同理其他的http类型的请求也可以通过tengine转发来解决https站点请求http的问题