1. 程式人生 > >Apache模塊壓縮和緩存設置

Apache模塊壓縮和緩存設置

手工 gcc 執行 信息 -s efault 卸載 module server

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 //檢查語法是否正確
技術分享圖片

Apache模塊壓縮和緩存設置