Web cache
1. Check if the mod_expires module is installed
apachectl -t -D DUMP_MODULES | grep "expires"
2. If the mod_expires module is not installed, recompile and install Apache to add the mod_expires module
systemctl stop httpd.service
cd /usr/local/httpd/conf/
mv httpd.conf httpd.conf.bak1
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel
cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--enable-deflate \
--enable-expires #加入mod_expires模块
make -j 4 && make install
3. Configure mod_expires module to enable
vim /usr/local/httpd/conf/httpd.conf
--52行--修改
Listen 192.168.199.10:80
--111行--取消注释
LoadModule expires_module modules/mod_expires.so #开启mod_expires模块
--199行--取消注释,修改
ServerName www.muzi.com:80
--末行添加--
<IfModule mod_expires.c>
ExpiresActive On #打开网页缓存功能
ExpiresDefault "access plus 60 seconds" #设置缓存60秒
</IfModule>
4. Check the installation and start the service
apachectl -t #验证配置文件的配置是否正确 httpd -t 是一样的效果
apachectl -t -D DUMP_MODULES | grep "expires" #检查 mod_expires 模块是否以安装
expires_module (shared) #已安装的正确结果
systemctl start httpd.service
5. Test whether the cache is effective
cat /usr/local/httpd/htdocs/index.html
方法一:
在Linux系统中,打开火狐浏览器,右击点查看元素
选择 网络 ---> 选择 HTML,WS,其他
访问 http://192.168.199.10 , 双击200响应消息查看响应头中包含 Expires 项
方法二
在Windows系统中依次安装Microsoft,NET4和fiddler软件,打开fiddler 软件
选择 inspectors ---> 选择 Headers
浏览器访问 http://192.168.199.10, 双击200响应消息查看 Expires 项