Apache 服务器反向代理另一个 Apache 服务器,获取“AH01102:从远程服务器读取状态行时出错”

问题描述 投票:0回答:3

我在两台独立的物理机器上设置了两台 Apache 服务器。我当前的设置是:

                      Apache 1 (Reverse Proxy) <===> Apache 2

两个 apache 服务器版本都

Apache/2.4.29 (Ubuntu)
Ubuntu 18.04.4 LTS
上运行,并且它们的
/etc/apache2/apache.conf
文件是相同的。

Apache 1 启用站点的配置:

<VirtualHost *:80>
        ServerName subdomain.domain.tld
        ServerAlias www.subdomain.domain.tld

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>

        ProxyRequests off
        ProxyPreserveHost On
        ProxyPass /maintenance_page !
        ProxyPass / http://[apache2-ip-address]:27300/ 
        ProxyPassReverse / http://[apache2-ip-address]:27300/
</VirtualHost>

Apache 2 启用站点的配置:

<VirtualHost *:27300>
        ServerName subdomain.domain.tld
        ServerAlias www.subdomain.domain.tld

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ErrorDocument 400 /notfound.html

        ProxyRequests off
        ProxyPreserveHost on
</VirtualHost>

如果我直接从网络浏览器中点击

http://[apache2-ip-address]:27300/
,apache 服务器登录页面就会正常显示。如果我在浏览器中输入
http://subdomain.domain.tld
,我会得到一个代理错误:

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

我在两台 Apache 服务器上都记录了跟踪记录。 Apache 服务器 2 正在接收来自 Apache 服务器 1 的代理请求,并向 Apache 服务器 1 返回一个 200 状态响应,非常好。流程在 Apache 服务器 1 处中断,我在其中看到以下日志:

[Sat Jul 11 20:34:08.671267 2020] [proxy:debug] [pid 32275:tid 140388069250816] proxy_util.c(3075): AH00962: HTTP: connection complete to [apache2-ip-address]:27300 ([apache2-ip-address])
[Sat Jul 11 20:34:08.671333 2020] [core:trace6] [pid 32275:tid 140388069250816] core_filters.c(525): [remote [apache2-ip-address]:27300] core_output_filter: flushing because of FLUSH bucket
[Sat Jul 11 20:34:08.677508 2020] [proxy_http:error] [pid 32275:tid 140388069250816] (104)Connection reset by peer: [client xx.xxx.xxx.xx:39014] AH01102: error reading status line from remote server [apache2-ip-address]:27300
[Sat Jul 11 20:34:08.677575 2020] [proxy_http:debug] [pid 32275:tid 140388069250816] mod_proxy_http.c(1324): [client xx.xxx.xxx.xx:39014] AH01105: NOT Closing connection to client although reading from backend server [apache2-ip-address]:27300 failed.
[Sat Jul 11 20:34:08.677624 2020] [proxy:error] [pid 32275:tid 140388069250816] [client xx.xxx.xxx.xx:39014] AH00898: Error reading from remote server returned by /
[Sat Jul 11 20:34:08.677681 2020] [proxy:debug] [pid 32275:tid 140388069250816] proxy_util.c(2192): AH00943: HTTP: has released connection for ([apache2-ip-address])
[Sat Jul 11 20:34:08.677724 2020] [http:trace3] [pid 32275:tid 140388069250816] http_filters.c(1128): [client xx.xxx.xxx.xx:39014] Response sent with status 502, headers:

我尝试过的事情,从我可以在网上找到的其他一些讨论,是对 apache server 1 启用站点的配置的以下更改:

  1. SetEnv proxy-initial-not-pooled 1
  2. SetEnv force-proxy-request-1.0 1
  3. SetEnv proxy-nokeepalive 1
  4. ProxyTimeout 600
  5. ProxyPass / http://[apache2-ip-address]:27300/ timeout=600
  6. ProxyPass / http://[apache2-ip-address]:27300/ nocanon

我已经用上述设置的几种组合强行解决了这种情况,但似乎没有任何效果。任何帮助表示赞赏。

我运行的另一项检查是,如果我在与任一 apache 服务器相同的机器上运行 nodejs 应用程序或 python flask 服务,并使用

ProxyPass / http://localhost:[port]/
代理该服务,则设置工作正常。因此,两台 apache 服务器都运行良好,并且能够在各自的本地主机上代理服务。任何中断都与两个 apache 服务器之间的通信有关。

更新: 与网络人员一起使用

curl
进行进一步分类后,问题似乎是组织防火墙只允许进入 apache 服务器 2 的入站流量并阻止可能导致 apache 服务器 1 出现 502 错误的出站流量。这似乎不是问题,直到我意识到我的笔记本电脑在测试时一直通过 VPN 连接到组织网络并且 apache 服务器 1 位于组织网络之外。如果这最终成为问题,那将是一个真正的无赖。

apache http proxy reverse-proxy
3个回答
4
投票

在 http.conf 文件中添加以下参数解决了我的“proxy: error reading status line from remote server”问题:

SetEnv proxy-initial-not-pooled 1

我从 Apache URL 中引用https://httpd.apache.org/docs/2.4/mod/mod_proxy_http.html

注意:重启http服务器再试


0
投票

在我的例子中,数据库连接错误触发了这个 Apache 的反向代理错误。


0
投票

我有同样的问题:它是由我使用

http
而不是
https
的错误协议引起的,它也可能是由超时引起的......所以检查你的日志和配置

© www.soinside.com 2019 - 2024. All rights reserved.