Apache作为具有子域的Tomcat的代理

时间:2014-12-23 08:14:33

标签: apache tomcat proxy confluence

即使我在SO上发现了类似的报道,但没有任何建议能解决我的问题。所以我决定自己提出一个问题。

我在Ubuntu上的Tomcat实例上运行Confluence(和Jira)作为WAR。该应用程序可通过http://localhost:8080/confluence访问。我想将apache配置为代理,以允许通过http://confluence.<servername>.de进行公共访问。按照https://confluence.atlassian.com/display/DOC/Using+Apache+with+mod_proxy#UsingApachewithmod_proxy-complex上的说明操作,我执行了以下步骤:

  • 将属性proxyName="confluence.<servername>.de"proxyPort="80"附加到 /var/lib/tomcat7/conf/server.xml 中的Connector元素。
  • /etc/apache2/sites-enabled/confluence.conf
  • 中定义了一个虚拟主机

confluence.conf 具有以下内容:

<VirtualHost *:80>
  ServerName confluence.<servername>.de

  ProxyRequests Off
  ProxyPreserveHost On

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

  ProxyPass / http://localhost:8080/confluence
  ProxyPassReverse / http://localhost:8080/confluence

  ProxyHTMLURLMap / /confluence/

  <Location />
    Order allow,deny
    Allow from all
  </Location>
</VirtualHost>

使用此配置,由于此(wget)输出,我无法调用http://localhost:8080/confluence

--2014-12-23 08:38:13--  http://localhost:8080/confluence
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://confluence.<servername>.de/confluence/ [following]
--2014-12-23 08:38:13--  http://confluence.<servername>.de/confluence/
Resolving confluence.<servername>.de (confluence.<servername>.de)... 92.51.163.197
Connecting to confluence.<servername>.de (confluence.<servername>.de)|92.51.163.197|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-12-23 08:38:13 ERROR 404: Not Found.

如果删除了proxyName和proxyPort属性,则可以进行此访问。但是,通过http://confluence.<servername>.de调用仍然会产生错误。 Apache日志的输出表明URL重写已损坏:

[Tue Dec 23 08:50:47.952647 2014] [authz_core:debug] [pid 24715:tid 140609413170944] mod_authz_core.c(828): [client 37.201.226.149:11808] AH01628: authorization result: granted (no directives)
[Tue Dec 23 08:50:47.952809 2014] [proxy:debug] [pid 24715:tid 140609413170944] mod_proxy.c(1104): [client 37.201.226.149:11808] AH01143: Running scheme http handler (attempt 0)
[Tue Dec 23 08:50:47.952838 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2020): AH00942: HTTP: has acquired connection for (localhost)
[Tue Dec 23 08:50:47.952851 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2072): [client 37.201.226.149:11808] AH00944: connecting http://localhost:8080/confluence to localhost:8080
[Tue Dec 23 08:50:47.953069 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2206): [client 37.201.226.149:11808] AH00947: connected /confluence to localhost:8080
[Tue Dec 23 08:50:47.953176 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2483): (111)Connection refused: AH00957: HTTP: attempt to connect to [::1]:8080 (localhost) failed
[Tue Dec 23 08:50:47.953277 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2610): AH00962: HTTP: connection complete to [::1]:8080 (localhost)
[Tue Dec 23 08:50:47.956860 2014] [proxy:debug] [pid 24715:tid 140609413170944] proxy_util.c(2035): AH00943: http: has released connection for (localhost)
[Tue Dec 23 08:50:47.988123 2014] [authz_core:debug] [pid 24715:tid 140609402681088] mod_authz_core.c(828): [client 37.201.226.149:11808] AH01628: authorization result: granted (no directives)
[Tue Dec 23 08:50:47.988231 2014] [proxy:debug] [pid 24715:tid 140609402681088] mod_proxy.c(1104): [client 37.201.226.149:11808] AH01143: Running scheme http handler (attempt 0)
[Tue Dec 23 08:50:47.988250 2014] [proxy:debug] [pid 24715:tid 140609402681088] proxy_util.c(2020): AH00942: HTTP: has acquired connection for (localhost)
[Tue Dec 23 08:50:47.988264 2014] [proxy:debug] [pid 24715:tid 140609402681088] proxy_util.c(2072): [client 37.201.226.149:11808] AH00944: connecting http://localhost:8080/confluenceconfluence/ to localhost:8080
[Tue Dec 23 08:50:47.988277 2014] [proxy:debug] [pid 24715:tid 140609402681088] proxy_util.c(2206): [client 37.201.226.149:11808] AH00947: connected /confluenceconfluence/ to localhost:8080
[Tue Dec 23 08:50:47.990134 2014] [proxy:debug] [pid 24715:tid 140609402681088] proxy_util.c(2035): AH00943: http: has released connection for (localhost)

我错过了什么吗?顺便说一句,如果我以URL http://<servername>.de/confluence用作代理的方式调整虚拟主机配置,一切正常。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我个人的偏好是在子文件夹中部署应用程序并设置代理:

ProxyPass "/confluence/" "http://localhost:8080/confluence/"
ProxyPassReverse "/confluence/" "http://localhost:8080/confluence/"

不需要ProxyHTMLURLMap,这可能就是为什么你看到“AH00944:将http://localhost:8080/confluenceconfluence/连接到localhost:8080”

设置与您的意图可能有点棘手,因为您需要将机器的完全限定域名设置为confluence.servername.de,并且您在本地DNS中也需要A记录。我是第二个Slash的问题:你能ping一下confluence.servername.de吗?

如果需要这样做,您可能还需要根据需要考虑使用这些指令:

ProxyRequests Off
ProxyVia Off
RemoteIPHeader X-Forwarded-For
RequestHeader    unset  Accept-Encoding
ProxyHTMLEnable On
ProxyHTMLExtended On
<Proxy *>
    Require all granted
</Proxy>