2009-02-20 45 views
3

由于horrible, horrible errors,我们改变了我们如何将Apache连接到Tomcat。我们使用mod_jk使用ProxyPass处理页面,但不使用图像

JkMount /path ajp13 

现在我们正在使用mod_proxy_ajp

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

然而,有一个特点,JkMount提供,但ProxyPass不会:在能力上的文件类型选择。这使代理html文件成为可能,而不是图像 - 换句话说,让快速的Apache服务于静态的东西,并且仅仅为了动态的东西而使用慢速的Tomcat。

JkMount /*.html ajp13 

有什么办法可以实现这个ProxyPass?可能使用周围的<Location>指令或类似的东西?

回答

5

使用ProxyPassMatch

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

编辑:马库斯·唐宁的修正

+0

使用正则表达式会影响性能吗? – 2009-02-20 23:08:33

+0

如果表达式过于复杂,则正则表达式有一些性能问题。对于这种正则表达式可以。 – kmkaplan 2009-02-23 07:44:50

1

不是你的问题,但一些需要注意的使用此配置。当使用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的旁边会令人困惑。

0

我们用下面让Apache处理图像并设置合理的过期头:

<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> 

然而,正如你可以看到,我们存储在我们的Tomcat应用程序之外的图像。我不知道它是否也适用于应用程序内的图像。