nginx代理配置解决wss协议访问失败问题

1、问题背景

系统访问地址可以正常登录,其它模块调用访问websocket协议时,报错

报错为: WebSocket connection to 'wss://cmi.hongchuanekji.com:50505/websocket/1_1536895492153057281_1a92e35…' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

 

2、解决方案:nginx.conf 配置应如下

#可直接配置在HTTP模块中,写到stream模块的方法试过没解决


server {
listen 50505 ssl;
server_name localhost;
ssl_certificate /app/nginx/hongchuankeji_com.pem;
ssl_certificate_key /app/nginx/hongchuankeji_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 https://192.168.7.12:50505;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

}
#需要新增这个location 配置
location /websocket/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
tcp_nodelay on;
proxy_pass https://192.168.7.12:50505;
}

posted @ 2022-07-05 11:33  平平无奇网瘾少女  阅读(786)  评论(0)    收藏  举报