我在几个地方问过这个问题,但是我没有find答案。 这应该是相当简单的和一个相当普遍的问题。 不幸的是,我对tomcat和mod_proxy一无所知,所以我无法弄清楚。
我有几个应用程序运行在tomcat,安装为战争,我可以访问他们在myserver.com:8080/myapp
我只是想创build一个Apache虚拟主机,使用mod_proxy将myapp.myserver.com转发到这个myserver.com:8080/myapp 。
哈德森是一个完美的例子,没有额外的configuration,只是一个部署的战争。 所以我设置了下面的apache vhost:
<VirtualHost *:80> ServerName hudson.myserver.ca ProxyPreserveHost On ProxyPass / http://localhost:8080/hudson ProxyPassReverse / http://localhost:8080/hudson </VirtualHost>
和我的proxy.conf是:
<IfModule mod_proxy.c> ProxyRequests Off <Proxy *> AddDefaultCharset off Order deny,allow Allow from all </Proxy> # Enable/disable the handling of HTTP/1.1 "Via:" headers. # ("Full" adds the server version; "Block" removes all outgoing Via: headers) # Set to one of: Off | On | Full | Block ProxyVia On </IfModule>
每个应用程序的每个请求都具有相同的行为。 例如,我去了hudson.myserver.ca,并由于某种原因转发到hudson.myserver.ca/hudson,这给了一个tomcat 404,说
The requested resource (/hudsonhudson/) is not available.
恰巧哈德森,杰拉,汇合,和任何其他应用程序。
什么是额外的“哈德森”,为什么不工作?
您的代理configuration应为:
ProxyPass / http://localhost:8080/hudson/ ProxyPassReverse / http://localhost:8080/hudson/
然后,您需要首先了解是什么导致了302redirect。 其他地方可能会有重写规则导致它。
在另一个说明中,您可能想考虑使用mod_proxy_ajp来代替Tomcat连接,因为这是它的目的。