Install and configure apache2 and mod_deflate in Linux

Source: Internet
Author: User

Install Apache

1. wget

Http://archive.apache.org/dist/httpd/httpd-2.2.13.tar.gz

2. In the installation directory

 

Let's take a look at the actual results. Please refer to the traffic in ten o'clock A.M.. After deflate compression is enabled, the bandwidth is 3 MB at today, and the deflate compression was not enabled at yesterday, the bandwidth is 4.3 MB. Obviously, it saves 30% of traffic expenses. If the number of images, zip files, and other files downloaded is small, there are many pure HTML pages and PHP pages, which can save more than 50% of the bandwidth.

 

 

Compression ratio test result (two pages ):

Original size: 30 KB
Gzipped size: 8 KB
Data savings: the 73.33% homepage is an HTML page, saving 73% of the bandwidth and increasing the speed by more than three times!

 

Original size: 37 KB
Gzipped size: 10 KB
Data savings: 72.97%, which is also an HTML page, saves 72% of the bandwidth and increases the speed by more than three times!

 

With real-time compression and transmission enabled, the CPU load is increased by about 0.3 in terms of server load, which is acceptable.

 

How to install deflate compression of Apache?

 

The following describes how to install and configure mod_deflate, which is applicable to apache2.x.

 

Mod_deflate compression is recommended for apache2. mod_gzip is suitable for apache1.x

 

For more information about mod_deflate, see http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

 

1. Search for the deflate Module
 

Find/backup/soft/httpd-2.2.4-name mod_deflate.c

CD/backup/soft/httpd-2.2.4/modules/Filters

2. Install mod_deflate

/Usr/local/apache224/bin/apxs-I-c-A mod_deflate.c

Apxs command parameters:
-I this option indicates that you need to install one or more dynamic shared objects to the modules directory of the server.
-A this option automatically adds a loadmodule row to the httpd. conf file to activate this module. Or, if this row already exists, it is enabled.
-A is similar to the-A option, but the loadmodule command it adds has a prefix (#), that is, this module is ready but not enabled.
-C this option indicates that the compilation operation is required. It will first compile the C source program (. c) files is the target code file (. o), and then connect the target code and other target code files in files (. O and. a) To generate a dynamic shared object dsofile. If the-O option is not specified, the output file name is inferred from the first file name in files, that is, the default file name is mod_name.so.
 
To install Apache, add -- enable-headers -- enable-deflate.

3. Configure mod_deflate

VI/usr/local/apacheapps/ CONF/httpd. conf
Loadmodule deflate_module modules/mod_deflate.so

This loadmodule must be placed after libphp5.so

<Ifmodule mod_deflate.c>
Deflatecompressionlevel 7
Addoutputfilterbytype deflate text/HTML text/plain text/XML application/X-httpd-PHP
Addoutputfilter deflate CSS JS
</Ifmodule>

There are two ways to adjust the compression level, but I am too lazy to study it. The default level is 6. The data compressed from an 890k file is only 1 K less than the maximum 9 levels, in addition, level 9 requires more CPU time, and the default level 6 is enough.

In addition, there is a real-time compression check tool that can detect whether a URL is compressed for transmission. It seems that this company is working on the zip compression program under IIS, so it has made such an online tool. Enter your address and press enter to check the server type, whether it is compressed or not, and compare the size before and after compression. In most cases, HTML code can be compressed to 1/4 ~ 1/3, Gzip compression transmission is still very good.

Compression Test: http://www.whatsmyip.org/mod_gzip_test/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.