Apache mod_deflate module Installation and configuration steps detailed

Source: Internet
Author: User
Tags vps

Recently moved the blog from the virtual host to the VPS, a natural toss. It is estimated that around this process, writing three or four blog posts is not a dream.
This is the first, server-side compression-the server before the content of the content to do gzip compression to reduce the size of the file transmitted-according to Google, can be reduced by 90%, but this is not the focus, the focus is server-side does not open gzip compression, Google pagespeed The test will be deducted-I personally care about the score.
Under Apache, the compression function is controlled by the Mod_deflate module.
Installation

My VPS system is loaded with OpenSUSE 13.1 64-bit system, Apache version is 2.4. First look at whether the Mod_deflate module has been installed in the system, I know there are two ways:
The current user executes the command httpd2-m, and the output is roughly as follows:

The code is as follows Copy Code
Chenxsan@zfanw.com:~> httpd2-m
[Fri Oct 31 13:13:59.278203 2014] [So:warn] [PID 9292] Ah01574:module Deflate_module is already loaded, skipping
Loaded Modules:
Core_module (Static)
Access_compat_module (Static)
So_module (Static)
Http_module (Static)
Mpm_prefork_module (Static)
Unixd_module (Static)
Systemd_module (Static)
Actions_module (Shared)
Alias_module (Shared)
Auth_basic_module (Shared)
Authn_file_module (Shared)
Authz_host_module (Shared)
Authz_groupfile_module (Shared)
Authz_user_module (Shared)
Autoindex_module (Shared)
Cgi_module (Shared)
Dir_module (Shared)
Env_module (Shared)
Expires_module (Shared)
Include_module (Shared)
Log_config_module (Shared)
Mime_module (Shared)
Negotiation_module (Shared)
Setenvif_module (Shared)
Ssl_module (Shared)
Userdir_module (Shared)
Reqtimeout_module (Shared)
Authn_core_module (Shared)
Authz_core_module (Shared)
Php5_module (Shared)
Rewrite_module (Shared)
Deflate_module (Shared)
To view the contents of the/etc/sysconfig/apache2 file, you can either open the file directly or use the grep command:
grep "apache_modules="/etc/sysconfig/apache2
The results are generally as follows:
apache_modules= "actions alias Auth_basic authn_file authz_host authz_groupfile authz_user autoindex CGI dir env expires in Log_config MIME negotiation setenvif SSL Userdir reqtimeout authn_core authz_core mod-userdir php5 mod_rewrite mod_d clude Eflate deflate "

The result I have shown here is that the Mod_deflate module has been installed.
If not, use A2enmod to enable:

The code is as follows Copy Code
sudo a2enmod deflate

Wait, why didn't you say the installation goes directly into the enabling phase? Because the Mod_deflate module has been loaded with Apache when it is installed, you can skip the installation step.
After you enable the Mod_deflate module, you need to restart the Apache server:

The code is as follows Copy Code
sudo rcapache2 restart

Enabled

Mentioned above.
Configuration

When you enable the Mod_deflate module, you are ready to configure it.
Can follow the instructions of OpenSUSE step-by-step, can also be rough direct point, modify the/etc/apache2/httpd.conf file, add the following code at the end of the file:

The code is as follows Copy Code

Setoutputfilter DEFLATE
Setenvifnocase request_uri\. (?: gif|jpe?g|png) $\
No-gzip dont-vary
Setenvifnocase request_uri\
\. (?: exe|t?gz|zip|bz2|sit|rar|7z) $\
No-gzip dont-vary
Setenvifnocase request_uri\.pdf$ No-gzip dont-vary

Browsermatch ^MOZILLA/4 gzip-only-text/html
Browsermatch ^mozilla/4\.0[678] No-gzip
Browsermatch\bmsie!no-gzip!gzip-only-text/html

Or you can consider the configuration provided by H5BP.
And then restart Apache:

The code is as follows Copy Code
sudo rcapache2 restart

Run another trip pagespeed, will not mention the server compression-Congratulations, you have compressed 90% of the transfer file size, saving a lot of bandwidth and time for users.

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.