[英]Using ProxyPass for pages but not images
由於可怕的錯誤 ,我們改變了將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>
指令或類似內容?
不是您的問題,而是使用此配置時要提防的問題。 當使用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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.