ApacheWebの最適化
ApacheWebの最適化
- はじめに:企業では、Apacheのデプロイ後にデフォルトの構成パラメーターのみが使用されるため、Webサイトに多くの問題が発生します。つまり、デフォルトの構成は、過去の下位サーバー構成用です。インターネット時代の発展に伴い、以前のデフォルト構成は、現在のUpには適用されなくなりました。
Webページの圧縮
1.mod_deflateモジュールがインストールされているかどうかを確認します
apachectl -t -D DUMP_MODULES | grep "deflate"
2. mod_deflateモジュールがインストールされていない場合は、Apacheを再コンパイルしてインストールし、mod_deflateモジュールを追加します。
systemctl stop httpd.service
cd /usr/local/httpd/conf/
mv httpd.conf httpd.conf.bak
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 #加入mod_deflate模块
make -j 4 && make install
3.mod_deflateモジュールを構成して有効にします
vim /usr/local/httpd/conf/httpd.conf
--52行--修改
Listen 192.168.199.10:80
--105行--取消注释
LoadModule deflate_module modules/mod_deflate.so #开启mod_deflate模块
--199行--取消注释,修改
ServerName www.muzi.com:80
--末行添加--
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript text/jpg text/png
#代表对哪些内容启用gzip压缩
DeflateCompressionLevel 9 #代表压缩级别,范围为1~9
SetOutputFilter DEFLATE #代表启用deflate模块对本站点的输出进行gzip压缩
</IfModule>
4.インストールを確認し、サービスを開始します
apachectl -t #验证配置文件的配置是否正确 httpd -t 是一样的效果
apachectl -t -D DUMP_MODULES | grep "deflate" #检查mod_deflate模块是否以安装
deflate_module (shared) #已安装的正确结果
systemctl start httpd.service
5.mod_deflate圧縮が有効かどうかをテストします
cd /usr/local/httpd/htdocs
先将music.jpg文件传到/usr/local/httpd/htdocs目录下
vim index.html
<html><body><hl>I opened my eyes last night and saw you in the low light.
Walking down by the bay, on the shore,staring up at the planes that aren't there anymore
I was feeling the night grow old and you were looking so cold
Like an introvert, I drew my over shirt.Around my arms and began to shiver violently before
You happened to look and see the tunnels all around me.Running into the dark underground</hl>
<img src="music.jpg"/>
</body></html>
方法一:
在Linux系统中,打开火狐浏览器,右击点查看元素
选择 网络 ---> 选择 HTML,WS,其他
访问 http://192.168.199.10 , 双击200响应消息查看响应头中包含 Content-Encoding:"gzip"
方法二
在Windows系统中依次安装Microsoft,NET4和fiddler软件,打开fiddler 软件
选择 inspectors ---> 选择 Headers
浏览器访问 http://192.168.199.10, 双击200响应消息查看Content-Encoding:"gzip"