I have this problem I am sure most of the people should have seen. I am using apache2's mod_proxy_html to forward web request to tomcat. The request got forward to tomcat, but tomcat server is unable to find web site resources(images, style, font...etc). The problem is, when use enter subdomain.example.com, Tomcat believe the resources path should be at: http://subdomain.example.com/xyz/images/images1.jpg.

This caused problem because in reality, because the http request become: http://www.example.com:8080/xyz/xyz/images/images1.jpg, context name "xyz" appear twice. Hence tomcat unable to locate image file. The file is actually at www.example.com:8080/xyz/images/images1.jpg

I believe this setup is quite standard, but I couldn't figure out how most people resolve this path issue?

This is my setup: 1. In my apache2 virtualHost config file, I have this setup:

<VirtualHost *:80>
ServerName subdomain.example.com

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  ProxyRequests Off
  ProxyPreserveHost On
  <Proxy *>
       Order deny,allow
       Allow from all
  ProxyPass / http://www.example.com:8080/xyz/
  ProxyPassReverse / http://www.example.com:8080/xyz/
  1. In Tomcat, my website is installed in */tomcat7/webapps/xyz

  2. I used ${pageContext.request.contextPath} to define base path for all my resources in my jsp page.



ProxyPass /xyz/ http://www.example.com:8080/xyz/

above the first ProxyPass line and you should be fine.

  • Confirmed, Tomcat doesn't like at all to have its resources remapped to a different context. And since we're at it, I'd suggest you to use the ajp proxy module, it will enable your web applications to obtain clients informations in a more transparent way, should you need it. – stoned Sep 2 '14 at 21:03
  • @stoned, thank for that, really appreciated the suggestion. The reason I use mod_proxy_html is because I want to keep it simple. I read it somewhere that in order for ajp protocol to work, apache have to convert html request to ajp and convert it back before send to client. I just thought it waste CPU time. Maybe I am missing the advantage of using mod_proxy ajp. can you elaborate on your point of obtain clients information in a more transparent way? what is the advantage of using mod_proxy_ajp? – Shawn Sep 2 '14 at 21:12
  • @Andras, sorry for the early post, I didn't read it properly. I am adding it now – Shawn Sep 2 '14 at 21:14
  • @Andras, stoned. Thanks both for the great suggestion. I worked! – Shawn Sep 2 '14 at 21:21
  • @Shawn, with mod_proxy_http apache will act as the client connecting to your application, and if you need to retrieve some details from the request object, you will soon enough notice that they will be Apache's server informations, not those from the remote client using the proxy. Not that you might need that for your project anyway. mod_proxy_html also tends to fail when proxying https to http or the opposite, mod_ajp works. We have mod_proxy_ajp working on several servers without a hitch or cpu spike, but we have only light loads, might not mean anything to you. – stoned Sep 2 '14 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.