微信小程序wss地址不允许使用端口,于是就利用nginx转发。
1、nginx版本是需要大于1.3
2、nginx配置文件修改
upstream websocket {
server ip:端口; //转发
}
server {
listen 443;
server_name 域名;
ssl on;
ssl_certificate 证书;
ssl_certificate_key 证书;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location /wss {
access_log /usr/share/nginx/logs/https-websocket.log;
proxy_pass http://websocket/; # 代理到上面
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite /wss/(.*) /$1 break;
proxy_redirect off;
}
}
3、GatewayWorker下的修改,用了nginx就不需要在此处使用ssl了,文档有提到 https://www.kancloud.cn/walkor/workerman/315297
$gateway = new Gateway("websocket://0.0.0.0:9993");
4、小程序那直接使用这个url : wss://域名/wss
感谢,学习了
大大的赞,希望有更多的人参与到开源事业中来
学习了,这么用挺好