收藏
回答

webSocket WS转WSS协议?

配置Nginx代理实现WS转WSS协议


nginx.conf 添加以下配置:

/etc/nginx/www.javays.com.key; /etc/nginx/www.javays.com_bundle.crt; 是SSL证书地址

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';
    }
}


wx.connectSocket({
  url: 'wss://www.javays.com/wss',
  header:{
    'content-type': 'application/json'
  }
})


最后一次编辑于  2022-10-09
回答关注问题邀请回答
收藏
登录 后发表内容