1, Nginx settings are as follows
-sharp websocket
upstream wss_svr {
server 192.168.213.182:1234 weight=1;
}
-sharp 443 sslwebsocketswss
server {
listen 443;
server_name www.a.com;
ssl on;
-sharp nginx.conf
ssl_certificate dhxtest.crt;
ssl_certificate_key dhxtest_nopass.key;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 SSLv2 SSLv3;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
ssl_verify_client off;
location / {
proxy_redirect off;
proxy_pass http://wss_svr; -sharp
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; -sharp
proxy_set_header Connection upgrade;
}
}
2, the WebSocket connection is as follows
ws = new WebSocket("wss://www.a.com");
ws.onopen = function() {
alert("");
ws.send("tom");
alert(":tom");
};
ws.onmessage = function(e) {
alert(":" + e.data);
};
3. If you connect through a port, you can wss://www.a.com:1234