Apache 2 Tomcat Virtual Host redirecting

2.3k Views Asked by At

I have a Java Web app in my tomcat, and I put Apache2 HTTP as my reverse proxy. Actually I already made a (quite) good redirection, but I wanna make it better.

My Virtual Host setting for redirecting to my tomcat web app is like below

<VirtualHost *:443>
   ServerAdmin [email protected]
   ServerName mywebapp.mydomain.com

   ProxyRequests off
   ProxyPreserveHost on
   ErrorLog /usr/log/tomcat/tomcat.error.log
   CustomLog /usr/log/tomcat/tomcat.log combined
   <Proxy *>
       Order deny,allow
       Allow from all
   </Proxy>
   ProxyPass / ajp://localhost:8009/MyWebApp
   ProxyPassReverse / ajp://localhost:8009/MyWebApp

   Redirect / /MyWebApp

   SSLEngine on
   SSLCertificateFile /etc/apache2/ssl/apache.crt
   SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>

With the above setting, I can reach my web app by typing: https://mywebapp.mydomain.com perfectly.

The only concern is: when my app is rendered on browser, I can see that the path is become like: https://mywebapp.mydomain.com/MyWebApp/view/home.action

Is there anyway I can make it becomes: https://mywebapp.mydomain.com/view/home.action

Without disclosing my app folder in tomcat, which is MyWebApp ?

1

There are 1 best solutions below

1
On

See if the following helps. I had used it a while back :

ProxyPass /MyWebApp/ ajp://localhost:8009/
ProxyPassReverse /MyWebApp/ ajp://localhost:8009/

  <Location /MyWebApp/>
    ProxyPassReverse /
  </Location>

Looks like the above did not work. I thought the Redirect directive that you have would take care of it. Can you attempt the following ?

RewriteEngine     on
RewriteRule ^(/.*)      ajp://localhost:8009/MyWebApp/$1    [P]

ProxyPass /MyWebApp/ /
ProxyPassReverse /MyWebApp/ /

  <Location /MyWebApp/>
    ProxyPassReverse /
  </Location>