Apache 2.2 Web 服务器的先前代理配置不适用于 Apache 2.4

Apache 2.2 Web 服务器的先前代理配置不适用于 Apache 2.4

在我之前的服务器上完美运行的 Apache 2.2配置。

一方面,这个完美运行的 Apache 2.2 配置的目的是充当负载均衡器对于运行于不同的 Tomcat

迁移到 Apache 2.4 后,配置的负载平衡部分是仍然完好并正常运转。

然而另一方面,在切换版本之后ProxyPass/ProxyPassReverse配置确实不行和以前一样。

这就是工作得很好ProxyPass/ProxyPassReverse 配置在 Apache 2.2 中如下:

<VirtualHost *:443>
        ServerName mysubdomain.xyz.com
        ProxyRequests Off
        ...
        <Location /manager_myhostname1>
             Order deny,allow
             Deny from all
             Allow from 12.34.56.78
             ProxyPass ajp://myhostname1:8009/manager route=myhostname1
             ProxyPassReverse ajp://myhostname1:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname1
        </Location>
        <Location /manager_myhostname2>
             Order deny,allow
             Deny from all
             Allow from 12.34.56.78
             ProxyPass ajp://myhostname2:8009/manager route=myhostname2
             ProxyPassReverse ajp://myhostname2:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname2
        </Location>
        <Location /manager_myhostname3>
             Order deny,allow
             Deny from all
             Allow from 12.34.56.78
             ProxyPass ajp://myhostname3:8009/manager route=myhostname3
             ProxyPassReverse ajp://myhostname3:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname3
        </Location>
</VirtualHost>

上述配置部分基本上有助于Tomcat 管理器页面负载平衡集群的各个主机是无障碍通过以下 URL:

- mysubdomain.xyz.com/manager_myhostname1
- mysubdomain.xyz.com/manager_myhostname2
- mysubdomain.xyz.com/manager_myhostname3

排除常见错误从 Apache 2.2 迁移到 2.4 时,我已将上述配置重写如下:

<VirtualHost *:443>
        ServerName mysubdomain.xyz.com
        ProxyRequests Off
        ...
        <Location /manager_myhostname1>
             Require ip 12.34.56.78
             ProxyPass ajp://myhostname1:8009/manager route=myhostname1
             ProxyPassReverse ajp://myhostname1:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname1
        </Location>
        <Location /manager_myhostname2>
             Require ip 12.34.56.78
             ProxyPass ajp://myhostname2:8009/manager route=myhostname2
             ProxyPassReverse ajp://myhostname2:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname2
        </Location>
        <Location /manager_myhostname3>
             Require ip 12.34.56.78
             ProxyPass ajp://myhostname3:8009/manager route=myhostname3
             ProxyPassReverse ajp://myhostname3:8009/manager
             SetOutputFilter proxy-html
             ProxyHTMLURLMap /manager /manager_myhostname3
        </Location>
</VirtualHost>

但这些改变都无济于事。访问 URL 时,mysubdomain.xyz.com/manager_myhostname1Apache 给出以下信息错误页面

<html>
    <head>
        <title>404 Not Found</title>
    </head>
    <body>
        <h1>Not Found</h1>
        <p>The requested URL /manager/ was not found on this server.</p>
        <hr>
        <address>Apache/2.4.25 (Debian) Server at mysubdomain.xyz.com Port 443</address>
    </body>
</html>

同样的错误适用于另外两个 URL。

看起来不管第一个正斜杠后面的部分将被重写为/manager而不是/manager_myhostname1(或类似地/manager_myhostname2/manager_myhostname3)。

  1. 我有哪个关键部分错过在迁移期间?
  2. 有没有明显的错误配置在上面的配置中?
  3. 为什么ProxyPass/ProxyPassReverse配置不再起作用,这样我就可以访问Tomcat 管理器页面/manager_myhostname1像我在 Apache 2.2 上那样引用的单个 tomcat 主机?

编辑:

我已经搜索过这些来源并尝试了不同的方法:


编辑@Gerald Schneider第一的评论:

道歉不使用CLI 工具执行请求:

myuser@myhomecomputer ~ $ wget -S https://mysubdomain.xyz.com/manager_myhostname1
--2019-05-14 15:59:27--  https://mysubdomain.xyz.com/manager_myhostname1
Resolving mysubdomain.xyz.com (mysubdomain.xyz.com)... 57.5.103.87
Connecting to mysubdomain.xyz.com (mysubdomain.xyz.com)|57.5.103.87|:443... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 302 Found
  Date: Tue, 14 May 2019 13:59:27 GMT
  Server: Apache-Coyote/1.1
  Location: /manager/
  Content-Length: 0
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
Location: /manager/ [following]
--2019-05-14 15:59:27--  https://mysubdomain.xyz.com/manager/
Reusing existing connection to mysubdomain.xyz.com:443.
HTTP request sent, awaiting response... 
  HTTP/1.1 404 Not Found
  Date: Tue, 14 May 2019 13:59:27 GMT
  Server: Apache/2.4.25 (Debian)
  Content-Length: 283
  Keep-Alive: timeout=5, max=99
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1
2019-05-14 15:59:27 ERROR 404: Not Found.

编辑@Gerald Schneider第二评论:

我已经添加了ProxyHTMLEnable On,但是它有没有效果无论如何,因为 wget 的输出与上面完全相同。


激活后编辑日志记录proxy_html负责代理 URL 映射的模块。日志现在包含以下几行:

[Wed May 15 10:35:01.671633 2019] [proxy:debug] [pid 26190] proxy_util.c(2418): [client 12.34.567.890:60476] AH00947: connected /manager to myhostname1:8009
[Wed May 15 10:35:01.672047 2019] [proxy:debug] [pid 26190] proxy_util.c(2884): AH02824: HTTP: connection established with 192.168.0.3:8009 (myhostname1)
[Wed May 15 10:35:01.672083 2019] [proxy:debug] [pid 26190] proxy_util.c(3051): AH00962: HTTP: connection complete to 192.168.0.3:8009 (myhostname1)
[Wed May 15 10:35:01.673241 2019] [proxy_http:trace3] [pid 26190] mod_proxy_http.c(1376): [client 12.34.567.890:60476] Status from backend: 302
[Wed May 15 10:35:01.673319 2019] [proxy_http:trace3] [pid 26190] mod_proxy_http.c(1647): [client 12.34.567.890:60476] start body send
[Wed May 15 10:35:01.673339 2019] [proxy:debug] [pid 26190] proxy_util.c(2171): AH00943: http: has released connection for (myhostname1)
[Wed May 15 10:35:01.673351 2019] [proxy_html:trace1] [pid 26190] mod_proxy_html.c(827): [client 12.34.567.890:60476] No content-type; bailing out of proxy-html filter

与代理服务器的连接似乎成功了,但最后一行显示No content-type; bailing out of proxy-html filter,表明proxy_html模块中的任何指令都是没有申请

答案1

我将配置改为这样:

<Location /manager_myhostname1>
    Require ip 12.34.56.78
    ProxyPass ajp://myhostname1:8009/manager route=myhostname1
    ProxyPassReverse ajp://myhostname1:8009/manager
    SetOutputFilter proxy-html
    ProxyHTMLURLMap /manager/ /manager_myhostname1/
</Location>

差异在于结束斜线ProxyHTMLURLMap。 (对于manager_myhostname2和类似manager_myhostname3

现在我可以使用以下 URL 访问各个管理器页面:

似乎当 Apache 获得从页面/manager/manager/html页面的重定向时,代理就被破坏了。该重定向是 Tomcat 内部执行的操作,但无法与 Apache 通信。

相关内容