Practical tips for optimizing Apache web pages

Apache web optimization

  • Foreword: In the enterprise, only the default configuration parameters are used after Apache is deployed, causing many problems for the website. In other words, the default configuration is for the lower server configuration in the past. With the development of the Internet era, the previous default configuration is no longer applicable to the present Up.

Web page compression

1. Check if the mod_deflate module is installed

apachectl -t -D DUMP_MODULES | grep "deflate"

Insert picture description here

2. If the mod_deflate module is not installed, recompile and install Apache to add the mod_deflate module

systemctl stop httpd.service
cd /usr/local/httpd/conf/
mv httpd.conf httpd.conf.bak

Insert picture description here

yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel

Insert picture description here

cd /opt/httpd-2.4.29/
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--enable-deflate               #加入mod_deflate模块

Insert picture description here

make -j 4 && make install

Insert picture description here

3. Configure mod_deflate module to enable

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>

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here
Insert picture description here

4. Check the installation and start the service

apachectl -t       #验证配置文件的配置是否正确   httpd -t  是一样的效果
apachectl -t -D DUMP_MODULES | grep "deflate"  #检查mod_deflate模块是否以安装
   deflate_module (shared)        #已安装的正确结果

systemctl start httpd.service

Insert picture description here
Insert picture description here

5. Test whether mod_deflate compression takes effect

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>

Insert picture description here
Insert picture description here

方法一:
在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"

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51614581/article/details/112319885