1. The console input code can connect successfully, but Mini Program cannot add a port, so it should be changed to a portless connection
.ws = new WebSocket("wss://:1234");
ws.onopen = function() {
alert("");
ws.send("tom");
alert(":tom");
};
ws.onmessage = function(e) {
alert(":" + e.data);
};
2. The server is Nginx
3. The reverse proxy setting on the pagoda panel does not work. I do not know if the setting is wrong
4
upstream websocket {
server ip:; //
}
server {
location /wss {
access_log /usr/share/nginx/logs/https-websocket.log;
proxy_pass http://websocket/; -sharp
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
rewrite /wss/(.*) /$1 break;
proxy_redirect off;
}
}
5. There is one thing I don"t know about my first contact. I suspended the website. Why ws = new WebSocket ("wss:// domain name: 1234");
can still connect successfully