无限星辰工作室-客户无限互联网动力之源

标题: nginx wss反代理配置(websocket) [打印本页]

作者: crx349    时间: 2023-6-16 23:38
标题: nginx wss反代理配置(websocket)
环境:

centos 7.9 x64
nginx
websocket 端口 6666

需求:
配置 nginx的443(ssl)端口反代理访问 websocket 的6666端口

1.解析域名如:www.xmspace.net 并申请和配置ssl证书

2.nginx站点配置添加如下内容:

  1. #PROXY-START/
  2. location  ~* \.(php|jsp|cgi|asp|aspx)$
  3. {
  4.     proxy_pass http://127.0.0.1:6666;
  5.     proxy_set_header Host $host;
  6.     proxy_set_header X-Real-IP $remote_addr;
  7.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  8.     proxy_set_header REMOTE-HOST $remote_addr;
  9. }
  10. location /
  11. {
  12.     proxy_pass http://127.0.0.1:6666;
  13.     proxy_set_header Host $host;
  14.     proxy_set_header X-Real-IP $remote_addr;
  15.     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  16.     proxy_set_header REMOTE-HOST $remote_addr;
  17.    
  18.     #持久化连接配置
  19.     proxy_connect_timeout 30s;
  20.     proxy_read_timeout 86400s;
  21.     proxy_send_timeout  30s;
  22.     proxy_http_version 1.1;
  23.     proxy_set_header Upgrade $http_upgrade;
  24.     proxy_set_header Connection "upgrade";

  25.     add_header X-Cache $upstream_cache_status;
  26.    
  27.     #Set Nginx Cache
  28.    
  29.             add_header Cache-Control no-cache;
  30.     expires 12h;
  31. }

  32. #PROXY-END/
复制代码

3.重启nginx 就可以用wss访问websocket了






欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://xmspace.net/) Powered by Discuz! X3.4