Apache配置----静态缓存
Apache配置----静态缓存
对于图片,html,css,Javascripts等,让客户端缓存,让访问不需要去服务器上访问,提高用户体验。
1.确定主配置文件是否开启mod_expires.c,模块,主机配置文件模块。
vi /usr/local/apache2/conf/httpd.conf
1)搜索:/expires
# 显示行号:set nu
2)搜索:/httpd-vhost
取消这行的注释
Include conf/extra/httpd-vhosts.conf
2.修改虚拟主机配置文件
vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
#在标签内添加如下内容(配置图片,css,html等缓存的时间)
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType image/gif "access plus 1 days"
ExpiresByType text/css "now plus 2 hours"
ExpiresByType text/html "access plus 2 days"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</ifmodule>
3.检查一下配置文件是否有语法错误
/usr/local/apache2/bin/apachectl -t
4.上传照片(xx.jpg)进行测试
rz
chmod 777 xx.jpg
5.重新加载httpd服务
/usr/local/apache2/bin/apachectl restart
# 如果有进程在启动,可以停掉它再启动
killall httpd #停掉http进程
6.关闭防火墙,setenforce
systemctl stop firewalld
setenforce 0
7.访问
浏览器:ip地址/xx.jpg
命令:curl -x ip地址:端口号 'http://www.007.com/xx.jpg' -I
# 状态码,Cache-Control(缓存时间)
感谢大家,点赞,收藏,关注,评论!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!