我在两台独立的物理机器上设置了两个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配置文件的内容:
SetEnv proxy-initial-not-pooled 1
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
ProxyTimeout 600
ProxyPass / http://[apache2-ip-address]:27300/ timeout=600
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网络之外。如果这是问题的原因,那就真是太糟糕了。