在nginx里配置如下:
upstream websocket {
server cloud.aaa.net:9050;# 远程websocket服务器地址
}
upstream web{
server cloud.aaa.net;# 远程http接口
}
server {
listen 443;#默认https和wss协议端口
ssl on;
ssl_certificate C:\phpStudy\Apache\conf\ssl\1_cloud.aaa.net_bundle.crt;
ssl_certificate_key C:\phpStudy\Apache\conf\ssl\2_cloud.aaa.net.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
underscores_in_headers on;#开启自定义头信息的下划线
#wss协议转发 小程序里面要访问的链接
location /wss {
proxy_pass http://websocket;#代理到上面的地址去
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
#https协议转发 小程序里面要访问的链接
location /{
proxy_pass http://web;#代理到原有的http的地址去
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Access-Control-Allow-Origin *;#跨域访问设置
}
}
以上配置,https正常,但是wss就是无法转发
2) //建立连接
wx.connectSocket({
url: “ws://cloud.aaa.net:9050”,
})
3)在服务器9050端口监听