我们使用以下内容让 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 应用程序之外。我不知道它是否也适用于应用程序内的图像。