2
votes

I've set up an Apache httpd server proxying requests to Tomcat using mod_proxy, listening on port 80. My only problem is that the static images and css is not appearing properly. If I use Tomcat as a server by itself on port 8080, the images and css appear fine. Any ideas how to display them? Thanks!

Note: I'm on a Mac and am using an Amazon EC2 server. An example would be very welcome.

4

4 Answers

1
votes

This issue refers to Path Translation, you might going to serve you'r application to the client at the top level /, but the corresponding path would be /myapp/(for example). Servlet applications running under tomcat are often setup in this way to provide multiple applications in one, you'r apache setup looks like it :

ProxyPass / http://localhost:8080/myapp/
ProxyPassReverse / http://localhost:8080/myapp/

you'r back-end application (myapp) is not aware of this translation and still hands out it's usual paths. for example you'r application refers to some static image files served by application running in tomcat at the location /myapp/images/, one of the way you can to do is keep special proxy mappings apart from other rewrite rules.

ProxyPass /myapp/images http://localhost:8080/myapp/images

ProxyPassReverse /myapp/images http://localhost:8080/myapp/images

so you can use these lines in front of previous directive block.

1
votes

Finally figured it out guys- please don't kick me when you read this. I'm using Apache2 with Spring 3, with Springsource Tool Suite as the IDE. The whole reason I wasn't able to get it running is because I was using this in my index jsp file:

<link rel="stylesheet" href="<spring:url value="/resources/styles/foo.css" htmlEscape="true" />" type="text/css"/>

The thing is, that when run on a Tomcat 7 server, its perfect. However, when run on an apache 2 server with tomcat as the container, this css file wasn't showing up. So I removed the / from /resources/styles/foo.css:

<link rel="stylesheet" href="<spring:url value="resources/styles/foo.css" htmlEscape="true" />" type="text/css"/>

It then worked perfectly, on both Apache+Tomcat and Tomcat standalone.

Thanks and sorry for wasting your time.

0
votes

In apache there is htdocs folder in that create a folder with name same as your project folder and paste resources in that and restart the server.

0
votes

Your apache error log will contain 404's for the images, note the URL's being used and either:

  • compare them to the ProxyPass directive you used and fix/add ProxyPass
  • Copy them to the right subdirectory of your webservers documentroot