0

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

Amir Keshavarz
  • 2,403
  • 3
  • 19
  • 19
  • Are you sure you should have the argument to ProxyPassMatch in quotes like that? ProxyPassMatch ^/(.*\.gif)$ ajp://localhost:8009/$1 If that doesn't work let me know and I'll get a local example running and will formulate an answer. (or someone else may post one before then ofcourse) should do it I think – Joeblade Dec 17 '15 at 08:48
  • In my test both models worked (with and without quotes), but in Apache documents it has quotes. https://httpd.apache.org/docs/2.4/mod/mod_proxy.html – Amir Keshavarz Dec 17 '15 at 11:18
  • ok that's new... the doc page I had open for mod_proxy didn't :) fair enough. and I see that your issue was to get more than 1 type of extension matched. I thought you had an error in config. my appologies I could've easily helped with that – Joeblade Dec 17 '15 at 16:04
  • No problem. Thank you @Joeblade – Amir Keshavarz Dec 17 '15 at 18:37

1 Answers1

0

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>
Amir Keshavarz
  • 2,403
  • 3
  • 19
  • 19