我在我的apache2.conf中使用下面的configuration
<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/gif "access plus 6 month" ExpiresByType image/jpg "access plus 6 month" ExpiresByType image/jpeg "access plus 6 month" ExpiresByType text/javascript "access plus 6 month" ExpiresByType text/css "access plus 6 month" ExpiresDefault "access plus 6 month" </IfModule>
它为css和js工作
curl -I example.com/assests/css/global.css Expires: Wed, 14 Jan 2015 09:28:17 GMT
但是当我curl任何图像文件
curl -I example.com/assets/images/banner-16-water-purifier.jpg Expires: Sun, 17 Aug 2014 09:29:10 GMT
正如你可以看到,j它不工作。 每张图片都一样(jpeg / png / gif)
您的configuration看起来正确,并在Apache 2.2.22上testing确定。 检查是否有任何重写apache.conf的mod_expires指令(ExpiresByType或ExpiresDefault)。
从图像path中的任何.htaccess文件开始,包括根networking文件夹/ assets /和/ assets / images /。 除非你禁止在这些文件夹中使用.htaccess,否则.htaccess中的指令将覆盖在其他地方设置的configuration。
接下来检查/ apache2 / sites-available /下的虚拟主机文件,然后检查apache2.conf中包含的任何其他configuration文件,例如/apache2/httpd.conf,/apache2/mods-available/expires.conf(如果存在)和/apache2/conf.d/下的任何文件。
当将mod_expire指令添加到虚拟主机configuration时,我遇到了类似的情况。 我想知道为什么当我将其设置为其他内容时,为什么仍显示30天到期,但是后来发现网站上的caching软件已将ExpiresByType和ExpiresDefault添加到.htaccess文件。