1.压缩功能的开启
yum remove httpd //卸载原有的Apache文件
cd /opt/LAMP
tar xzvf httpd-2.4.2.tar.gz -C /opt //手工编译安装httpd
tar xzvf apr-1.4.6.tar.gz -C /opt //支持Apache上层应用跨平台,提供底层接口库
tar xzvf apr-util-1.4.1.tar.gz -C /opt
cd /opt
cp -R apr-1.4.6/ /opt/httpd-2.4.2/srclib/apr
cp -R apr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util
yum install -y gcc gcc-c++ pcre pcre-devel zlib-devel //安装环境软件包(pcre : 一个Perl库,支持正则表达式)
cd /opt/httpd-2.4.2
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
grep -v "#" /usr/local/httpd/bin/apachectl > /etc/init.d/httpd //启动脚本
vim /etc/init.d/httpd 在文件最前面插入下面的行
#!/bin/sh
chkconfig:2345 85 15
description:Apache is a World Wide Web server.
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig --list httpd
chkconfig --level 35 httpd on //给脚本执行权限及开机自启动
ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf //建立软连接便于管理
vim /etc/httpd.conf
cd /usr/local/httpd/bin
./apachectl -t //检查httpd.conf的语法
vim /etc/httpd.conf
LoadModule deflate_module modules/mod_deflate.so //开启压缩功能模块
在文件末尾插入如下信息
<IFModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript //可压缩文件类型
DeflateCompressionLevel 9 //压缩比
SetOutputFilter DEFLATE //支持压缩模块的类型(DEFLATE)
</IfModule>
./apachectl -t -D DUMP_MODULES | grep "deflate" //检查压缩功能模块是否开启
2.缓存设置
./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-expires \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
grep -v "#" /usr/local/httpd/bin/apachectl > /etc/init.d/httpd
vim /etc/init.d/httpd 在文件最前面插入下面的行
#!/bin/sh
chkconfig:2345 85 15
description:Apache is a World Wide Web server.
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig --list httpd
chkconfig --level 35 httpd on //给脚本执行权限及开机自启动
ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
vim /etc/httpd.conf
LoadModule expires_module modules/mod_expires.so //开启缓存功能模块
在文件末尾插入如下信息
</IfModule>
<IFModule mod_deflate.c>
ExpiresActive On
ExpiresDefault "access plus 50 seconds"
</IfModule>
cd /usr/local/httpd/bin
./apachectl –t //检查语法是否正确
转载于:https://blog.51cto.com/13842738/2164962