无限星辰工作室-客户无限互联网动力之源
标题:
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站点配置添加如下内容:
#PROXY-START/
location ~* \.(php|jsp|cgi|asp|aspx)$
{
proxy_pass http://127.0.0.1:6666;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
proxy_pass http://127.0.0.1:6666;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
#持久化连接配置
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
add_header Cache-Control no-cache;
expires 12h;
}
#PROXY-END/
复制代码
3.重启nginx 就可以用wss访问websocket了
欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://xmspace.net/)
Powered by Discuz! X3.4