Apache - Tomcat ProxyPass VirtualHost - Context Path

孤人 提交于 2019-12-04 13:31:46

问题


I have a problem configuring apache tomcat ProxyPass directive for two applications that have two different Context Paths in tomcat. The tomcat is running behind an apache and I use the apache to proxy path the requests to tomcat. In apache I want to access both application via a hostname instead of a context path.

Scenario:

tomcat

https://domain:8443/app1
https://domain:8443/app2

in tomcat the applications have the context path app1 and app2

in apache I want to enable both application as follow:

https://app1.host/
https://app2.host/

In apache I have created a configuration for each domain:

ProxyPass /  https://localhost:8443/app1
ProxyPassReverse / https://localhost:/8443/app1

The strange thing is app1 is only available through apache using the context path:

https://app1.host/app1

Is it possible to realize such a setup with apache ProxyPass module?

Thx for your help.


回答1:


You should be able to achieve the result you want by using virtual hosting. Also it's a good idea to pass the requests to tomcat via the AJP protocol instead of HTTPS. Try adding this to the Apache configuration

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName app1.host
    ProxyPass / ajp://localhost:8009/app1/
</VirtualHost>

<VirtualHost *:443>
    ServerName app2.host
    ProxyPass / ajp://localhost:8009/app2/
</VirtualHost>

If you haven't changed the default server settings for Tomcat this should work just as it is. Otherwise make sure to specify the AJP port that is configured in Tomcat's conf/server.xml file. There should be a line similar to this:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Make sure that you have the mod_proxy and mod_proxy_ajp modules loaded in Apache configuration, this may vary depending on your Apache installation. Also remove any previously configured 'ProxyPass / ...' lines as they will interfere with the new configuration. Hope this works for you.




回答2:


you can try

ProxyPass /  https://localhost:8443/app1/
ProxyPassReverse / https://localhost:8443/app1/

with the final /



来源:https://stackoverflow.com/questions/2607922/apache-tomcat-proxypass-virtualhost-context-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!