前提:应用已支持SSL,NGINX已有SSL配置。加入以下配置便支持wss
location /wss/ { proxy_pass http://127.0.0.1:端口/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; }
前端连接:
var ws = new WebSocket("wss://域名/wss/");