配置Nginx代理实现WS转WSS协议
nginx.conf
upstream websocket { server 119.91.250.33:8088; } server { listen 443 ssl; server_name www.javays.com; ssl_certificate /etc/nginx/www.javays.com_bundle.crt; ssl_certificate_key /etc/nginx/www.javays.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass http://119.91.253.38:8080; } location /wss { proxy_pass http://websocket/; proxy_read_timeout 60s; proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'Upgrade'; } }
js
var ws = new WebSocket("wss://www.javays.com/wss");