Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've configured Apache web server and Tomcat like this:

I created a new file in apache2/sites-available, named it "myDomain" with this content:

<VirtualHost *:80>


ProxyPass / ajp://localhost:8009

<Proxy *>
AllowOverride AuthConfig
Order allow,deny
Allow from all
Options -Indexes


Enabled mod_proxy and myDomain

a2enmod proxy_ajp
a2ensite myDomain

Edited Tomcat's server.xml (inside the Engine tag)

<Host name="" appBase="webapps/myApp">
<Context path="" docBase="."/>
<Host name="" appBase="webapps/myApp">
<Context path="" docBase="."/>

This works great. But I don't like to put static files (html, images, videos etc.) into {tomcat home}/webapps/myApp's subfolders instead I'd like to put them the apache webserver's root WWW directory's subdirectories. And I'd like Apache web server to serve these files alone.

How could I do this? So all incoming request will be forwarded to Tomcat except those that ask for a static file.

share|improve this question
up vote 1 down vote accepted

You probably want to use ProxyPassMatch. You can use it like:

ProxyPassMatch ^(/.*\.cgi)$ ajp://localhost:8009$1

to proxy all requests ending in .CGI. If you wish to proxy multiple extensions just add more lines or edit the regex. Then you just have to make sure your VirtualHost is setup to serve the remaining image types.

share|improve this answer
but this redirects to the tomcatHome/webapps/myApp/ location static files in the var/www folder – Hunter Feb 27 '11 at 2:37
Then just add a DocumentRoot /var/www to the VirtualHost section. Then with the above ProxyPassMatch all .cgi requests will be proxied and everything will be served directly from /var/www. – uesp Feb 27 '11 at 14:55
It works! Thanks! – Hunter Feb 28 '11 at 12:57

While uesp's answer is technically correct, I always recommend that people use the Apache mod_jk connector to host Java Application servers over Apache. In general, it simplifies, well... everything, and allows you to mount specific contexts. For example, you can now just use:

LoadModule     jk_module   libexec/
JKMount        /myapp/*    ajp13

It makes forwarding requests much easier, and also gives you a lot more flexibility in using Apache to host other resources.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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