Apache配置----静态缓存

45 篇文章 5 订阅

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(缓存时间)

感谢大家,点赞,收藏,关注,评论!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cat God 007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值