Search code examples
springsecurityurlproxyajp

Remove context name from URL - mod_proxy_ajp with Spring Security


I have a app named "FitnessTracker" running on tomcat, post 8080. I am using Spring Security, and everything works fine when I test it directly on tomcat using http://localhost:8080/FitnessTracker

I then configured mod_proxy_ajp on Apache http 2.2, to access using a domain name, below is my VirtualHost configuration:

<VirtualHost *:80>
    ServerName www.testing.com
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    RewriteEngine on 
    RewriteRule ^/FitnessTracker/(.*)$ /$1 [P]

    ProxyPass /  ajp://localhost:8009/FitnessTracker/
    ProxyPassReverse / ajp://localhost:8009/FitnessTracker/
</VirtualHost>

Now, when I access www.testing.com/ - it gets redirected to www.testing.com/FitnessTracker/login.html

Is there a way to not have /FitnessTracker/ in the URL? I would like to hide the tomcat Context name from the URL. Ideally, I want the URL to look like www.testing.com/login.html I know that this is due to the RewriteRule, but without the rewrite rule spring security with mod_proxy doesn't work - since Spring security redirects to login page along with context name.

Please let me know if you have suggestions.


Solution

  • I think you forgot to rewrite the cookie domain and cookie path. Check ProxyPassReverseCookieDomain directive. From the backend perspective the request path still has to look like /FitnessTracker/