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(缓存时间)
感谢大家,点赞,收藏,关注,评论!