大网数据广告活动
服务器运维问答

nginx : no live upstreams while connecting to upstream

· 52CE 我爱测

502 bad gateway error displayed when switching between site pages and some times on home page but not for the first request on the home page it is only when another page redirect to it. and it happens for some javascript files lo…

问题原文

原帖链接 · Mohammad Jolani · CC BY-SA 3.0

502 bad gateway error displayed when switching between site pages and some times on home page but not for the first request on the home page it is only when another page redirect to it. and it happens for some javascript files

load balancing configured on two upstreams php1 php2 both are apache server.

When I checked error log i fond:

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/"

and this is load balancing server configuration

  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;
      }

    }

I searched for hours and nothing helpful found my streams are up and no problems with them.

社区高分解答

原帖链接 · Mark Stosberg · CC BY-SA 3.0

This is not a problem with Nginx, it is a problem with your PHP backends not responding in time. You can add logging to Nginx to help confirm this.

As a second point of reference, you can you can top on the server and manually check if PHP is slamming the CPU for periods of time, another indicator of slow responses.

If very slow responses from PHP are OK with you, you can ask Nginx to wait longer before giving up:

 # Wait 5 minutes before giving up on the backend!
 proxy_read_timeout 5m; 

By examining the logs with the timing information linked to above, you ought to be able to figure out which requests are slow for PHP to process.

To narrow down the problem, send these requests directly to the PHP backend.

Depending on what's happening, you might also be able enable caching of some requests in Nginx, avoiding some of slow requests.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-04-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。