微信开发要求 必须用https 和 wss连接, 这里给出nginx反向代理配置, 自己使用一切正常,希望能帮助大家。域名一定要在微信开发后台设置,不然连接不上, 域名要备案,不然 审核不通过。
nginx.conf 添加两行
wss.conf 如下
- upstream login_websocket {
- server 120.*.*.*:20013 weight=1;
- server 120.*.*.*:20014 weight=1;
- server 120.*.*.*:20012 weight=1;
- }
- upstream baseapp_websocket0 {
- server 120.*.*.*:20015;
- }
- upstream baseapp_websocket1 {
- server 120.*.*.*:20016;
- }
- upstream baseapp_websocket2 {
- server 120.*.*.*:20017;
- }
- upstream web {
- server www.**.cn:8081; #域名 端口自己设置
- }
- server {
- listen 443;
- #server_name www.goworldcup.cn
- ssl on;
- ssl_certificate /usr/local/nginx/conf/server.crt;
- ssl_certificate_key /usr/local/nginx/conf/server.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;
- location /login {
- proxy_pass http://login_websocket;#代理到上面的地址去
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "Upgrade";
- }
- location /baseapp0 {
- proxy_pass http://baseapp_websocket0;#代理到上面的地址去
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "Upgrade";
- }
- location /baseapp1 {
- proxy_pass http://baseapp_websocket1;#代理到上面的地址去
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "Upgrade";
- }
- location /baseapp2 {
- proxy_pass http://baseapp_websocket2;#代理到上面的地址去
- 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 *;#跨域访问设置
- }
- }