Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache - Tomcat ProxyPass VirtualHost - Context Path

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.

like image 792
Arne Avatar asked Apr 09 '10 13:04

Arne


People also ask

What is ProxyPass and ProxyPassReverse in httpd conf?

The "ProxyPass" and "ProxyPassReverse" parameters are used to tell Apache how to proxy requests. They require the "mod_proxy.so" and "mod_proxy_http.so" Apache modules, which are loaded by default in RHEL5 and RHEL6, but check the following lines are uncommented in the "/etc/httpd/conf/httpd. conf" file to make sure.

Where is ProxyTimeout set?

The directive ProxyTimeout can be placed in: server config and under virtual host.

What is proxy preserve host?

The ProxyPreserveHost directive is used to instruct Apache mod_proxy, when acting as a reverse proxy, to preserve and retain the original Host: header from the client browser when constructing the proxied request to send to the target server.


2 Answers

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.

like image 80
Andrius Avatar answered Oct 20 '22 14:10

Andrius


you can try

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

with the final /

like image 30
enrico.devita Avatar answered Oct 20 '22 12:10

enrico.devita