Nginx配置WebSocket
2020-12-28 08:31
标签:soc for 现在 替换 改变 out 匹配 没有 均衡 先直接展示配置文件,如下所示(使用的话直接复制,然后改改ip和port即可) 接下来,我们就分别分析上述配置的具体含义。 首先: 表示的是: 其次: 表示的是 nginx负载均衡: 最后: 表示的是监听的服务器的配置 Nginx配置WebSocket 标签:soc for 现在 替换 改变 out 匹配 没有 均衡 原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/13846496.htmlmap $http_upgrade $connection_upgrade {
default upgrade;
‘‘ close;
}
upstream wsbackend{
server ip1:port1;
server ip2:port2;
keepalive 1000;
}
server {
listen 20038;
location /{
proxy_http_version 1.1;
proxy_pass http://wsbackend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
‘‘ close;
}
upstream wsbackend{
server ip1:port1;
server ip2:port2;
keepalive 1000;
}
server {
listen 20038;
location /{
proxy_http_version 1.1;
proxy_pass http://wsbackend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}