How to enable gzip compression for server performance optimization policies

Source: Internet
Author: User

This article introduces how to configure gzip compression for nginx, lighttpd, and apache2 server environments to optimize server performance. For more information, see.

Nginx configuration gzip Compression

By default, gzip compression of Nginx is disabled, and only text/html is compressed. You need to edit nginx. conf file. Add the configuration in the http segment. The common configuration snippets are as follows:

The Code is as follows: Copy code

Gzip on;
Gzip_comp_level 6; # The larger the compression ratio, the longer the compression time. The default value is 1.
Gzip_types text/xml text/plain text/css application/javascript application/x-javascript application/rss + xml; # which files can be compressed
Gzip_disable "MSIE [1-6]."; # IE6 is invalid

Enable gzip of apache2

At the time of Official Development of apache2, we have taken the web page compression into account and built the mod_deflate module. Therefore, apache2 does not need to use mod_gzip. The working principles of the two are similar, there is also the module that enables the page compression of mod_deflate, which has similar functions and efficiency as mod_gzip. Even better, you do not need to use the mod_gzip module.

Configuration file instance:

The Code is as follows: Copy code

<Ifmodule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE js css
</Ifmodule>

Configure gzip in lighttpd

Gzip configuration mainly uses the compress Module
1. Activate the compress module and remove the comments of mod_compress in the lightppd. conf file.
2. Configure the compressed file storage directory compress. cache-dir. Note that the user running lighttpd must have the read and write permissions for this directory. The compressed file type compress. filetype
3. Change the dynamically generated php file gzip to php. ini, and add zlib. output_compression = On and zlib. output_handler = On.
4. Restart lighttpd

Configuration file instance:

The Code is as follows: Copy code

Compress. cache-dir = "/home/flymouse/lighttpd/compress /"
Compress. filetype = ("text/plain", "text/html", "application/x-javascript", "text/css", "application/javascript ", "text/javascript ")

Related Article

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.