As requested in the comments, I've included an example of how to server 2 separate webapps via the same sub-domain using Apache ProxyPass
and ProxyPassReverse
.
The way I've done it is with standard HTTP proxy but its also possible to do with AJP connector (I believe). I think this requires one of the webapps to be running under a different tomcat (due to server.xml
requiring a unique Host
entry - see below but I'm not 100% sure about this).
Add the following to your Apache conf file (e.g. vhosts.conf or vhosts.d/servername.conf):
<VirtualHost *:80>
ServerName 127.0.0.1
ServerName externalName1
ProxyRequests Off
# AJP example
#ProxyPreserveHost On
#ProxyPass / ajp://localhost:8009/
#ProxyPassReverse / ajp://localhost:8009/
ProxyPass /ws http://internalName1:8080/webapp1/
ProxyPassReverse /ws http://internalName1:8080/webapp1/
ProxyPass / http://internalName2:8080/webapp2/
ProxyPassReverse / http://internalName2:8080/webapp2/
</VirtualHost>
Because the order of the ProxyPass entries decides the precedence, any requests for /ws/*
will always go to the first server. But the first server has to have a /ws
controller to respond to these requests - in other words /ws
is NOT the context path of the app but an internal path to the webapp. webapp2
can contain paths that include /ws
but they will simply be ignored as all requests will go to webapp1
.
Each webapp needs a Host
entry in the tomcat server.xml
file, something like:
<Host name="externalName1" debug="0" appBase="webapps/webapp1" unpackWARs="true" autodeploy="true">
<Alias>serverName1AltName</Alias>
<Context path="" docBase="" debug="5" reloadable="true"/>
</Host>
I've not configured this myself for quite a few years and have pulled the info from a few servers we have running, so I apologise if there are any mistakes or errors.