微信小程序WebSocket 访问Nginx报错:WebSocket handshake: Unexpected response code: 400

open的时候报错

wx.onSocketOpen(function(res){ 

     console.log("WebSocket连接已打开!");

});

先停止Nginx (windows 版)
tasklist | findstr nginx(查看nginx进程)

taskkill /pid xxxx /F (杀进程)

location /st2 {

        root  html;

        index  index.html index.htm;

        proxy_pass http://xxxxxxxx:xxxx/;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "Upgrade";

}

加上这三句

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "Upgrade";

问题解决(这是其中一种情况)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。