当前位置: 首页 > 工具软件 > WSS > 使用案例 >

nginx 代理部署wss

翟志新
2023-12-01
  1. nginx 配置
location ^~ /websocket {
 proxy_redirect off;
 proxy_pass http://127.0.0.1:8180;   #转发
 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;   #升级协议头
 proxy_set_header Connection upgrade;
}
  1. js websocket
  var uri = "wss://xxx/websocket";
  // 打开一个 web socket
  var ws = new WebSocket(uri);
 类似资料: