考虑以下nginx
配置。我有两个 node js 服务器分别在端口8008
和上运行9008
。当我关闭服务器上的服务器时,我502
的服务器出现错误。我已通过交换端口并重新加载配置验证了服务器上的服务器是否正常工作。为什么我会看到错误?access.log
8008
9008
502
upstream backend {
server localhost:8008 max_fails=1 fail_timeout=3s;
server localhost:9008 backup;
}
server {
listen 80;
server_name app.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name app.domain.com;
ssl_certificate ssl/chained.crt;
ssl_certificate_key ssl/server.key;
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache off;
proxy_cache_bypass $http_upgrade;
}
}
答案1
它与有关Connection: keep-alive
。与后端具有活动连接的客户端不会立即知道它即将关闭,因此会尝试通过同一连接向同一后端服务器发出未来请求。