本帖最后由 ppgjx 于 2022-11-8 21:38 编辑
我现在有个websocket服务器 链接是 ws://localhost:8282
有个域名 www.qq.com
然后我得nginx是这样设置的
[Asm] 纯文本查看 复制代码 map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server localhost:8282; # appserver_ip:ws_port
}
server {
server_name [url=http://www.qq.com]www.qq.com[/url];
location / {
proxy_pass http://websocket;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
这样的配置是没问题的 也就是websocket链接地址由ws://localhost:8282改成了 ws://www.qq.com
现在有个问题 只把www.qq.com/websocket这个地址转发过去 我是这样配置的
[Asm] 纯文本查看 复制代码 map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server localhost:8282; # appserver_ip:ws_port
}
server {
server_name [url=http://www.qq.com]www.qq.com[/url];
location /websocket/ {
proxy_pass http://websocket;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
现在按理来说我使用ws://www.qq.com/websocket 是不是应该等于 ws://localhost:8282/websocket
但是我测试是连不通 ws://www.qq.com 也是连不同有大佬知道是哪里问题吗
|