Using ProxyPass for pages but not images

10,539

Solution 1

Use ProxyPassMatch:

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

Edited: Marcus Downing’s correction

Solution 2

kmkaplan's post is the right answer, but it gave me the error:

Syntax error on line 32 of .../httpd-vhosts.conf:
ProxyPass Unable to parse URL

It worked when I changed the directive to read:

ProxyPathMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

I can only assume that putting the $1 right next to the port number 8009 was confusing it.

Solution 3

Not your issue but something to watch out for using this configuration. While using apache mod_proxy to connect to tomcat my error log was showing dropped connections under moderate load. Adding this to httpd.conf solved my problems.

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
Share:
10,539
Marcus Downing
Author by

Marcus Downing

Full stack web developer and sysadmin with an interest in language design, anime and all things oriental.

Updated on June 28, 2022

Comments

  • Marcus Downing
    Marcus Downing almost 2 years

    As a result of horrible, horrible errors, we've changed how we connect Apache to Tomcat. We were using mod_jk:

    JkMount /path ajp13
    

    Now we're using mod_proxy_ajp:

    ProxyPass /path ajp://localhost:8009/path
    ProxyPassReverse /path ajp://localhost:8009/path
    

    However, there's a feature that JkMount offered but ProxyPass doesn't: the ability to select on file types. This made it possible to proxy html files, but not images - in other words, to let the nice fast Apache serve the static stuff, and resorting to the slow Tomcat only for the dynamic stuff.

    JkMount /*.html ajp13
    

    Is there any way of achieving this with ProxyPass? Possibly using a surrounding <Location> directive or something like that?