微信小程序真机调试无法连接websocket
配置Nginx
配置如下:
upstream websocket{
server 域名:8880;
}
server {
server_name 域名; ##需要代理的域名
listen 443 ssl;
ssl_certificate ***.pem; ## SSL pem;
ssl_certificate_key ***.pem; ## SSL pem;
# cert文件夹需要自己建
# ssl_certificate /usr/local/nginx/cert/**.pem;
# ssl_certificate_key /usr/local/nginx/**.key;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /ws {
proxy_pass https://websocket/ws; ## 关键部分
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 60s;## 默认为60s
proxy_send_timeout 60s;##默认为60s
break;
}
}
}
小程序连接
wx.connectSocket({
url: 'wss://域名/ws'
})