2009-02-20 32 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應用程序之外的圖像。我不知道它是否也適用於應用程序內的圖像。