我最近在支持 Apache2 的 VPS 上部署了一个网站,并且正在研究 YSlow 的性能改进建议。这些改进包括使用 mod_deflate 和 mod_expires,由于我有 root 访问权限,我可以直接编辑 Apache 配置文件。
mod_deflate 现在正在工作,但是我遇到了 mod_expires 的问题,所以这就是我所做的:
启用 expires 模块并重新启动服务器
a2enmod expires
service apache2 restart
在 mods_enabled 下创建一个新文件“expires.conf”,其中包含以下内容:
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
但是,当检查网络下的各种浏览器开发工具时,文件显示无缓存控制。
我想在位于我网站根目录的 .htaccess 中使用上面的 mod_expires 脚本:/var/www/sitename/public_html,因为 .htaccess 中的设置会覆盖 apache 配置文件中的任何先前设置。
为此,我在 apache2.conf 中启用了 htaccess。
我通过自愿在其中引入错误来测试我的 htaccess 文件确实可以正常工作(注释掉 IfModule 打开标记)。刷新浏览器给了我一个 500 服务器错误。因此正在处理 htaccess 文件。
不幸的是,浏览器开发工具仍然没有显示缓存控制,我的想法已经不多了。
我错过了什么吗?谢谢!