环境:
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了
|
|
|
|
|