Preface
The first two articles talk about Aapche's access control and log analysis, this article will focus on Apache web optimization, such as: page compression, Web page caching.
In the process of using Aapche as a Web server, we have to optimize the configuration of the Aapche server for better performance, so we need the configuration optimization for the Aapche server!
Web page compression
There is always a reason why, why should we compress the page, with this problem to see the next operation. We also often surf the internet, we will know that the speed of access to the site has many factors, such as: Application response speed, network bandwidth, server performance and so on! One of the most important factors is the response speed of the Aapche itself. So if your home site performance is not ideal, it is the first time to adjust the Aapche server execution speed, using Web compression can increase the speed of the application!
The most important thing is: do not need any fees ~ do not need any fees ~ do not need any fees ~ important things to say three times
HTTP Compression Process
1 · After the Web server receives the browser's HTTP request, first check whether the browser supports HTTP compression;
2 · If the browser supports HTTP compression, the Web server would check the suffix name of the requested file;
3 · If the suffix name of the requested file is: HTML, CSS and other static files, the Web server will compress the cache directory to check whether the existing request file of the latest compressed file;
4 · If the compressed file of the requested file does not exist, the server returns the uncompressed request file to the browser and stores the compressed file in the compressed cache directory;
5 · If the latest compressed file of the requested file already exists, the compressed file of the requested file is returned directly;
6 · If the file is requested dynamically, the server compresses the content dynamically and returns to the browser, but the compressed content is not stored in the cache directory.
Here are two demo diagrams
Gzip Not used:
To open using gzip:
Aapche Compression Module
Mod_deflate compression speed is a bit faster, while mod_gzip compression ratio is slightly higher
Mod_deflate is specifically designed to ensure server performance and use of a compression module, in layman's terms, if your site visits are small, recommend the use of Mod_gzip, if you have a large number of site visits, recommend the use of Mod_deflate module compression.
At the beginning of the Apache2.0.45 version mod_deflate can set the compression level to adjust the speed and quality of compression, so it is more perfect, can be set by your needs freely. The value of the adjustment is: 1~9 (default = 6)
Web cache
The Web cache is a page cache that is often not changed or rarely changes, and the next time the browser accesses these pages again, it does not need to download the pages again, thus increasing the user's access speed
Apache's Mod_expires module automatically generates the express label and Cache-control tag in the header information of the page, and the client browser determines that the next visit is to fetch the page in the local machine's cache, without having to make a request to the server again. This reduces the frequency and number of visits to the client, reducing unnecessary traffic and increasing access speed.
Installing the Mod_deflate, Mod_expires module
Recompile to install Apache, add mod_deflate, Mod_expires module contents to parameters
The content of the edits is as follows: in GCC gcc-c++ pcre pcre-devel zlib-devel? Yum is good and then in.
./configure--prefix=/usr/local/httpd--enable-deflate--enable-so--enable-rewrite--enable-charset-lite-- enable-cgi--enable-expires
Make && make install
Ln-s/usr/local/httpd/conf/httpd.conf/etc/httpd.conf #为了管理, make a link to facilitate
Edit the master configuration file
Vim/etc/httpd.conf
The contents of the amendment are as follows:
LoadModule headers_module modules/mod_headers.so #去掉注释, open the head module
LoadModule deflate_module modules/mod_deflate.so #去掉注释, turn on the compression module
LoadModule filter_module modules/mod_filter.so #去掉注释, start filter module
LoadModule expires_module modules/mod_expires.so #去掉注释, turn on the cache module
Listen 192.168.100.20:80
#Listen 80
ServerName www.baidu.com:80
Add the following two zones at the end of the Apache master configuration file:
<ifmodule mod_deflate.c>
Addoutputfilterbytype DEFLATE text/html text/plain text/css test/xml test/javascript
Deflatecompressionlevel 9
Setoutputfilter DEFLATE
</IfModule>
In the compression module, add the supported compressed file format and compression ratio of 9, you can modify
The way to support the compression module is deflate
<ifmodule mod_expires.c>
Expiresactive on
ExpiresDefault "Access plus seconds"
</IfModule>
Web cache mode on, cache time is 50 seconds!
Restart Service
Service httpd Start
Service Iptables Stop
Setenforce 0
Verify using the Fiddler Grab Kit tool:
Summarize
Optimization of the server can increase the speed of the customer's access.
Using the compression module can prompt the page loading speed without any cost.
Web cache also provides access speed from a certain base, it is to temporarily store some resources locally, set a certain period of time, when you are in the access, you do not need to request the server, but directly from the local cache.
Induction
This article is mainly about the 2-point optimization of the Web page:
1 • Compression of the Web page, the compression module used is: Mon_deflate. Why use it, personally feel it's a feature can use the Deflatecompressionlevel directive to set the compression level, so that the quality of compression, and the speed of control in their own hands
2 • Caching of Web pages, using the Cache module is: Mon_expires. It can reduce the frequency and number of client access, to reduce unnecessary traffic and increase the speed of access!
3 · If the clutch does not see the compression effect, then in the Apache site to add a picture bar, or just a few characters, no compression effect.
[Super Detail] Apache Web Optimization: Web page compression and Web cache Super Detail