1

I run a Spring App on a remote server where is installed a Tomcat Server which give access to my app via https://mydom.com:8080/myapp.

To make my app accessible via https://mydom.com, I installed Apache and configured as reverse proxy.

This is configuration:

<VirtualHost _default_:443>

   SSLEngine On

   SSLCertificateFile /opt/ssl/mydom_com.crt
   SSLCertificateKeyFile /opt/ssl/mydom_com.key
   SSLCertificateChainFile /opt/ssl/mydom_com.ca-bundle

   BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
   SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL

   ServerName mydom.com

   ProxyRequests Off
   ProxyPreserveHost On
   ProxyPass / http://127.0.0.1:8080/myapp/
   ProxyPassReverse / http://127.0.0.1:8080/myapp/
   ProxyPassReverseCookiePath /myapp /

</VirtualHost>

Now, I try to use ${pageContext.request.contextPath} in my jsp files to get the right links and resources path.

When I run from IDE it return /myapp, which is good.

When run on mydom.com it return /myapp, which is not good. I need to get an empty string or /.

How I can configure to get right value for ${pageContext.request.contextPath}?

2
  • what you want to access through that url mydom.com? Commented Jul 18, 2019 at 17:04
  • my app from tomcat which run via https://mydom.com:8080/myapp. But I have done that with apache. My problem is at ${pageContext.request.contextPath}. On mydom.com it returns /myapp which is contextPath from tomcat: https://mydom.com:8080/myapp. On mydom.com I want ${pageContext.request.contextPath} to be equal with '/' or ''(empty string). Commented Jul 19, 2019 at 9:00

1 Answer 1

2

Change your mapping from:

ProxyPass / http://127.0.0.1:8080/myapp/
ProxyPassReverse / http://127.0.0.1:8080/myapp/
ProxyPassReverseCookiePath /myapp /

to:

ProxyPass /myapp/ http://127.0.0.1:8080/myapp/
ProxyPassReverse /myapp/ http://127.0.0.1:8080/myapp/

And all your problems will be solved.

Trying to re-write context paths in the proxying is the #1 cause of insanity in Tomcat administrators. Just don't do it.

If you want your application available on /, then do one of these things:

  1. Re-direct / to /myapp/ and use my re-written mapping above
  2. Re-name your application from /myapp/ to / on the Tomcat end and fix your mapping to map / -> /

Any other configuration will be an endless cycle of band-aids, fix-ups and band-aids-to-fix-ups that you will have to apply.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. First option is excluded for me. I want my website to be accessible via mydom.com, not mydom.com/myapp. So I picked second option. I renamed my app ROOT.war and copied in webapps folder. There can be another way to done it or only ROOT.war is the only way?
You have a few options, but ROOT.war is pretty much the easiest possible way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.