It's no longer considered a good idea to keep your static content under Apache and your dynamic content under Tomcat for simple performance reasons. If you need multiple apps to share these resources, that's different, but not because of some reason that became obsolete over a decade ago.
That URL can point anywhere in the world. Not only does it not have to be within the Tomcat webapp, it doesn't have to be on the same server, or literally even in the same country. Look at almost any commercial webpage and you'll see URL references to a whole host of third-party contributors.
So all you really need is an independent Apache source for the static content. You can do that by setting up a separate Apache VirtualHost for the images (say, http://static.myhost.com/images/pic1.gif) or you can just do an Apache mod_rewrite to rewrite the image URL requests as Apache-hosted URLs.
An IDE is no substitute for an Intelligent Developer.
Joined: Jan 24, 2011
Thanks. Could you please provide me the sample on setting up the virtual hosts to server static content from apache
In httpd.config, I have:-
NameVirtualHost <IP address>:80
<VirtualHost <IP address>:80>
Allow from all
Allow from all
I can't give step-by-step details - at least not without sending you a bill - but there are a couple of general things you should be aware of.
First, there are (at least) 2 different ways to connect Apache to Tomcat. The older one is to use mod_jk. The newer one is to use mod_proxy. In either event, you define the URL pattern you want to use for requests sent on to Tomcat as part of the proxy configuration. For example, using mod_proxy:
That makes any request sent to myvirtualhost/tomcat go to Tomcat. If you want to, you can use "/" as the URL root pattern, and EVERYTHING will go to Tomcat.
If you set up URL rewriting, you can rewrite your image and CSS requests to go to local directories instead of being routed to the ProxyPass URL.