真机调试 websocket 失效怎么办?

小程序 文章 2021-03-29 15:41 877 0 全屏看文

AI助手支持GPT4.0

真机调试 websocket 失效怎么办?What should I do if the websocket fails when debugging on the real machine?

真机调试 websocket 失效怎么办?

在小程序中已经设置好socket合法域名了,在开发者工具中运行🆗,但是在真机调试的时候就连接不上了,很奇怪!

小程序尝试发布,发布审核过了上线了,但是依旧无法访问。

在社区中也看到过有类似提问,但是貌似都没有好的解决方案。

另外,我服务器跑在3333端口,我想应该是可以指定端口的吧?

The socket legal domain name has been set in the small program, and run in the developer tool 🆗 , but in the real machine debugging time can't connect, very strange! Small program tried to release, release audit online, but still unable to access. I have seen similar questions in the community, but it seems that there is no good solution. In addition, my server runs on port 3333. I think it can specify the port, right?

回答:

Mr.Zhao:

删除小程序,然后重新扫码访问

Salieri:早试过了😂 😂 ,这么简单我也不会问了,卡了有两天了。
Mr.Zhao:简单?越简单越粗心,这个都能卡两天。资源全在你手里,别人只能猜
Salieri:

真机调试后变成

看到社区有人把这当作bug来反馈了。。

维她命系:

可以配置服务端代理转发,参考以下nginx转发websocket配置,小程序连接websocket地址为:wss://abc.com/websocket

location /websocket {        proxy_pass http://127.0.0.1:3333;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header Host $host;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "Upgrade";        proxy_set_header X-Real-IP $remote_addr;}
Salieri:问一个小问题吧😀,配置nginx是必要的吗?
维她命系:小程序后台socket域名怎么配置的?有没有设置端口?
Salieri:emm,wss://www.xxxx.cn:3333,我是这么写的
Salieri:真机调试后变成xhr了,有头绪吗?

-EOF-

AI助手支持GPT4.0