当我使用nginx代理服务时,为什么localhost和localhost之间有这么多tcp连接。 这是我的nginx代理配置:
server {
listen 80;
server_name www.domain1.com;
location /{
proxy_pass http://localhost:4999;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
server_name www.domain2.com;
location /{
proxy_pass http://localhost:4999;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
}
答案 0 :(得分:0)
Nginx在这里充当反向代理,为一个http请求建立客户端代理tcp连接和代理服务器tcp连接(http keep-alive将重用tcp conn)
我猜在配置proxy_pass http://localhost:4999;
的客户端关闭客户端代理后,代理服务器连接将被关闭
您可以尝试以下配置:
upstream backend {
server localhost:4999;
keepalive 10;
}
server {
listen 80;
server_name www.domain2.com;
location /{
proxy_pass http://backend;
}
}