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

8

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

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

两个 Apache 服务器版本都是运行在 Ubuntu 18.04.4 LTS 上的 Apache/2.4.29 (Ubuntu),它们的 /etc/apache2/apache.conf 配置文件是相同的。

Apache 1 的 sites-enabled 配置:

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

        ServerAdmin webmaster@domain.tld
        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的sites-enabled配置:

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

        ServerAdmin webmaster@domain.tld
        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服务器1 sites-enabled配置文件的内容:
  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与网络人员一起进行调试,问题似乎是org防火墙仅允许入站流量到达apache服务器2并阻止出站流量,这可能导致apache服务器1上出现502错误。在测试期间我没有意识到这一点,因为我的笔记本电脑一直连接着org网络的VPN,并且apache服务器1位于org网络之外。如果这是问题的原因,那就真是太糟糕了。
3个回答

4
在http.conf文件中添加以下参数可以解决我的"proxy: error reading status line from remote server"问题:
SetEnv proxy-initial-not-pooled 1

我得到了Apache网址的参考 https://httpd.apache.org/docs/2.4/mod/mod_proxy_http.html 注意:重新启动HTTP服务器并再次尝试。

1
http.conf 在 ubuntu 上是 apache2.conf...花了一段时间才弄明白这个 - Dagmar

1

我曾经遇到过同样的问题:它是由于我使用了错误的协议 http 而不是 https 导致的,也可能是由于超时引起的...所以请检查您的日志和配置文件。


不仅虚拟主机中的HTTP很重要,你从浏览器或代理访问网站的方法也很重要。我使用了Cloudflare,并且它试图在端口443上使用SSL来访问端口80上的HTTP服务器。 - Felix Farquharson

0
在我的情况下,数据库连接错误触发了这个Apache反向代理错误。

1
我认为我遇到了类似的情况...反向代理Apache配置存在一些小问题,导致超时。一旦我解决了这些问题,问题就消失了。 - Dagmar
1
一年晚了...但是,令人印象深刻的是,看似不相关的小事情可能会变成巨大的麻烦。 - Alison Moura

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接