【问题标题】:Bad gateway error with Nginx load balancing?Nginx负载平衡的网关错误?
【发布时间】:2015-10-28 22:22:40
【问题描述】:

我有三台服务器,我的主服务器、我的辅助服务器和我的负载平衡器。我正在使用 Nginx 作为负载均衡器,但出现了一个错误的网关错误。

在我的 Nginx 站点配置文件中的负载均衡器上,我有:

upstream backend {
        server 1.1.1.1:80;
        server 1.1.1.2:80;
}

在我的服务器块中,我有:

location / {
    proxy_pass http://backend;
}

在我的 nginx 错误日志中,我收到“从上游读取响应标头时上游过早关闭的连接”

当我转到负载平衡器 IP 1.1.1.3 时,我收到了错误的网关错误。有什么办法解决这个问题?

【问题讨论】:

  • 这与你的 Nginx 配置无关,假设地址是正确的。
  • 这有什么关系?我在主服务器上的访问/错误日志中没有看到任何异常?
  • 你为什么要这样做?你没有连接到它。如果您从代理盒到其中一个后端执行curl 或等效项,您应该会看到它失败。

标签: nginx load-balancing


【解决方案1】:

你缺少几个参数

您的上游缺少 keepalive

    server 1.1.1.1:80;
    server 1.1.1.2:80;
    keepalive 64;

尝试添加这些

proxy_redirect          off;
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_set_header        Host                    $http_host;
proxy_set_header        X-NginX-Proxy           true;
proxy_set_header        Connection "";
proxy_http_version      1.1;
proxy_cache_key         sfs$request_uri$scheme;
proxy_pass              http://backend;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 2021-10-14
    • 2023-03-14
    • 1970-01-01
    • 2015-03-14
    • 2013-04-09
    • 2022-01-10
    • 2019-07-17
    相关资源
    最近更新 更多