作为可怕,可怕的错误,我们”已经改变了我们的Apache连接到Tomcat。我们使用mod_jk

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>指令或类似的东西?

有帮助吗?

解决方案

使用 ProxyPassMatch

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

<子>编辑:马库斯唐宁的校正

其他提示

不是你的问题,但一些需要注意的使用此配置。虽然使用Apache的mod_proxy连接到tomcat我的错误日志中显示中等负荷下掉线。 添加这httpd.conf中解决我的问题。

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 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被混淆了。

我们使用以下方法来让Apache的服务的图像,并设置合理的Expires头:

<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应用程序之外的图像。我不知道这是否也适用于应用程序内的图像。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top