Using ProxyPass for pages but not images

As a result of terrible, terrible errors, we have changed the way Apache connects to Tomcat. We used mod_jk:

JkMount /path ajp13

Now we use mod_proxy_ajp:

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

However, there is a function offered JkMount, but it ProxyPassdoes not allow: to select file types. This made it possible to proxy html files, but not images - in other words, for a good fast Apache to serve static things and resort to slow Tomcat only for dynamic stuff.

JkMount /*.html ajp13

Is there any way to achieve this using ProxyPass? Perhaps a district directive is used, <Location>or something like that?

+3
4

ProxyPassMatch:

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

: Marcus Downings

+5

, -, . apache mod_proxy tomcat . httpd.conf .

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
+1

kmkaplan - , :

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

, :

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

, $1 8009 .

+1

We use the following for Apache to serve images and set reasonable expiration headers:

<Virtualhost *:80>
    ServerName domain.com
    ServerAlias *.domain.com

    Alias /img/ /var/www/domain/img/
    <Directory /var/www/domain/img/>
        ExpiresActive On
        ExpiresByType image/gif "access plus 1 months"
        ExpiresByType image/jpg "access plus 1 months"
        ExpiresByType image/jpeg "access plus 1 months"
        ExpiresByType image/png "access plus 1 months"
        ExpiresByType image/x-icon "access plus 1 months"
        ExpiresByType image/ico "access plus 1 months"
        # This will prevent apache from having to check for a .htaccess file on each request.
        AllowOverride None
        # Allow symlinks. Otherwise, apache will make a separate call on each filename to ensure it is not a symlink.
        Options +FollowSymLinks -SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

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

    # Prevent domain.com/img from being served by Tomcat
    ProxyPass /img !

    # Pass all other requests to Tomcat
    ProxyPass / ajp://localhost:8009/

    # 1. Note that usually no ProxyPassReverse directive is necessary. The AJP request includes
    #    the original host header given to the proxy, and the application server can be expected to
    #    generate self-referential headers relative to this host, so no rewriting is necessary. 
    # 2. If you still want to use it, read this first:
    #    http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
    # ProxyPassReverse / http://domain.com/
</Virtualhost>

However, as you can see, we save images outside of our Tomcat application. I do not know if it works for images inside the application.

0
source

Source: https://habr.com/ru/post/1703576/


All Articles