小程序要求
- 按照小程序官方配置要求,須要域名支持wss,且不能有端口,因此只能是80或443
- wss 方式請求,對應的nginx須要配置https,ws方式就是http方式
nginx配置
server {
listen 443;
server_name xxx.com;
ssl on;
ssl_certificate /data/nginx/sslkey/cinyi.cer;
ssl_certificate_key /data/nginx/sslkey/cinyi.key;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
#配置支持wss小程序,必須是443端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
proxy_pass http://192.168.20.152:8083;
}
}
- nginx配置主要就這兩行 proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'Upgrade';