环境
uniapp写微信小程序,使用webSocket连接后台spring boot通信
在开发环境中使用 ws://xxx 连接正常,
但是微信小程序需要配置https访问,webSocket需要使用 wss:// 来连接,
使用wss:// 域名 访问时,一直连接不上,多方查找发现,
需要在 服务器的nginx的443转发上加一个配置
location /ai {
rewrite ^/ai/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9152/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
root html;
index index.html index.htm;
}
主要是这两句
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “Upgrade”;