Apache web page and security optimization------compression

In an enterprise, only using the default configuration parameters after deploying Apache will cause many problems on the website. In other words, the default configuration is for the previous low-level server configuration, and the previous configuration is no longer suitable for the current Internet era.
In order to meet the needs of enterprises, it is necessary to consider how to improve the performance and stability of Apache, which is the content of Apache optimization.

--------Web page compression--------

1. Check whether the mod_deflate module is installed

apachectl -t -D DUMP_MODULES | grep "deflate"

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

 

 

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 && make install

 

 

3. Configure the mod_deflate module to enable

vim /usr/local/httpd/conf/httpd.conf

--line 52--Modify

Listen 192.198.80.10:80

 

 

--105 line -- uncomment

LoadModule deflate_module modules/mod_deflate.so        #开启mod_deflate 模块

 

--line 199--uncomment, modify

ServerName www.kgc.com:80

 

 

--Add at the end--

<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. Check the installation and start the service

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

 

 

 

systemctl start httpd.service

5. Test whether mod_deflate compression is effective

cd /usr/local/httpd/htdocs
先将game.jpg文件传到/usr/local/httpd/htdocs目录下
vim index.html
<html><body><h1>It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!It works!</h1>
<img src="game.jpg"/>
</body></html>

 

 

 

Guess you like

Origin blog.csdn.net/2302_76824193/article/details/130943791