javaapachetomcatmod-proxy-ajp

Using mod_proxy_ajp for a java portal on Tamcat+Apache


I have a java portal running on Tomcat but I want its static contents(except html) to be served by Apache httpd. So I've installed an Apache httpd and now I am configuring httpd.conf I know that I need something like the below text:

<VirtualHost *:80>
DocumentRoot /opt/tomcat/webapps/ROOT
ServerName mywebapp.com
ServerAlias mywebapp.com
ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPassMatch "^/(.*\.gif)$" "ajp://localhost:8009/$1"
ProxyPassReverse  /  ajp://localhost:8009/

But this is a sample and I do not know how to use RegEx in front of ProxyPassMatch to fulfill my purpose.

My purpose is to serve jpg, jpeg, gif, js, css by Apache httpd And others serving by Tomcat


Solution

  • I found a solution:

    <VirtualHost *:80>
        DocumentRoot /opt/tomcat/webapps/ROOT
        ServerName mywebapp.com
        ServerAlias mywebapp.com
        ProxyRequests Off
        ProxyPreserveHost On
    
        <Proxy *>
        Order deny,allow
        Allow from all
        </Proxy>
    
        #ProxyPass         /  ajp://localhost:8010/
        ProxyPassMatch ^/(.*(?<!\.jpg)(?<!\.png)(?<!\.jpeg)(?<!\.css)(?<!\.ico)(?<!\.bmp)(?<!\.js)(?<!\.gif))$ ajp://localhost:8009/$1  
    
        ProxyPassReverse  /  ajp://localhost:8009/
    </VirtualHost>