Apache网页优化 ----网页缓存
程序员文章站
2022-06-25 21:42:20
...
Apache网页优化 ----网页缓存
一、Apache的网页缓存
Apache 的mod_expries 模块会自动生成页面头部信息中的 Express标签和 Cache-Control 标签。
客户端浏览器根据标签决定下次访问是在本地机器的缓存中获取页面,不需要再次向服务器发出请求,从而降低客户端的访问频率和次数,达到减少不必要的流量和增加访问速度的目的。
二:实验步骤
1、先关闭防火墙,挂载文件,并解压到/opt/目录下
[aaa@qq.com ~]# systemctl stop firewalld.service
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# mkdir /abc
[aaa@qq.com ~]# mount.cifs //192.168.10.29/share /abc
[aaa@qq.com ~]# cd /abc
[aaa@qq.com abc]# tar zxvf apr-1.6.2.tar.gz -C /opt/
[aaa@qq.com abc]# tar zvxf apr-util-1.6.0.tar.gz -C /opt/
[aaa@qq.com abc]# tar zxvf httpd-2.4.2.tar.gz -C /opt/
2、在/opt/目录下将apr两个包移动到httpd-2.4.2/sriclib 下
[aaa@qq.com opt]# mv apr-1.6.2/ httpd-2.4.2/srclib/apr
[aaa@qq.com opt]# mv apr-util-1.6.0/ httpd-2.4.2/srclib/apr-util
3、手工编译安装所需源码包,并到httpd-2.4.2目录下开始进行源码编译
[aaa@qq.com opt]# ls httpd-2.4.2/srclib/
apr apr-util Makefile Makefile.in
[aaa@qq.com httpd-2.4.2]# yum install gcc gcc-c++ pcre* zlib-devel expat-devel make -y
[aaa@qq.com opt]# cd /opt/httpd-2.4.2/
[aaa@qq.com opt]# cd httpd-2.4.2/
[aaa@qq.com httpd-2.4.2]# ./configure \ //执行configure脚本
> --prefix=/usr/local/httpd \ //指定文件安装路径
> --enable-so \ //开启核心功能
> --enable-rewrite \ //开启重写功能
> --enable-charset-lite \ //开启字符集
> --enable-cgi //开启cgi脚本支持
[aaa@qq.com httpd-2.4.2]# make && make install
4、创建软连接,并对主配置文件进行修改
[aaa@qq.com httpd-2.4.2]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
[aaa@qq.com httpd-2.4.2]# vim /etc/httpd.conf
(1)修改监听地址
Listen 192.168.73.166:80
#Listen 80
(2)修改域名
ServerName www.kg.com
(3)在末尾加上
LoadModule expires_module modules/mod_expires.so
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 50 seconds"
</IfModule>
(4)开启 expires_module 模块
5、验证apache是否设置成功
[aaa@qq.com httpd-2.4.2]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[aaa@qq.com httpd-2.4.2]# apachectl -t
Syntax OK ‘启动成功’
6、开启apache服务,并验证模块开启
[aaa@qq.com httpd-2.4.2]# service httpd start ‘开启服务’
[aaa@qq.com httpd-2.4.2]# netstat -ntap | grep httpd ‘查看接口’
[aaa@qq.com extra]# /usr/local/httpd/bin/apachectl -t -D DUMP_MODULES | grep "expires" ‘验证模块开启’
expires_module (shared)