服务器常见Nginx错误汇总
1.nginx:no live upstreams while connecting to upstream
no live upstreams while connecting to upstream
[error] 27212#0: *314 no live upstreams while connecting to upstream, client: ip_address , server: example.com, request: "GET / HTTP/1.1", upstream: "http://example.com", host: "example.com", referrer: "http://example.com/mypages/"
fail_timeout=15s其实就是如果上次请求发现服务无法正常返回,那么有15s的时间该server会不可用,但是一旦超过15s请求也会再次转发到该server上的,不管该server到底有没有真正的恢复。
upstream example.com {
# ip_hash;
server php01 max_fails=3 fail_timeout=15s;
server php02 max_fails=3 fail_timeout=15s;
}
server {
listen IP:80;
server_name example.com;
access_log /var/log/nginx/example.com.access;
error_log /var/log/nginx/example.com.error error;
location / {
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_set_header X-Forwarded-Proto $scheme;
proxy_pass http://$server_name/$uri;
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;
proxy_no_cache $http_pragma $http_authorization;
}
}
如果你用过nginx plus其实你会发现nginx plus 提供的health_check机制更加强大,说几个关键词,你们自己去查! zone slow_start health_check match ! 这个slow_start其实就很好的解决了缓存预热的问题,比如nginx发现一台机器重启了,那么会等待slow_starts设定的时间才会再次发送请求到该服务器上,这就给缓存预热提供了时间。
2.nginx:connect() failed (110:connection timed out )while connecting to upstream
[error] upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: howtounix.info, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080", host: "howtounix.info", referrer: "requested_url"
nginx配置如下: