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 ") |