Detailed nginx server configuration in the open file gzip compression method _nginx

Source: Internet
Author: User
Tags auth curl nginx server

Gzip (Gnu-zip) is a compression technique. After gzip compressed page size can be changed to the original 30% or even smaller, so that users browse the page when the speed will be much more. Gzip compressed page need both browser and server support, is actually server-side compression, upload browser after the browser decompression and resolution. Browsers don't need us to worry because the vast majority of browsers now support parsing gzip-enabled pages.
The Nginx compression output has a set of gzip compression instructions to implement. The instructions are located between two curly braces in http{.
Here's a little bit about configuring the gzip compression method:

1, VIM open nginx configuration file

Vim/usr/local/nginx/conf/nginx.conf

2, to find the following paragraph, to modify

gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 16k;
#gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml text/javascript image /jpeg image/gif image/png;
Gzip_vary off;
Gzip_disable "MSIE [1-6]\.";

3. Explain

Line 1th: Open gzip

Line 2nd: No compression critical value, greater than 1K compression, generally do not need to change

Line 3rd: Buffer, yes, well, no explanation, no change.

Line 4th: With the reverse agent, the end of the communication is http/1.0, there should be no need to see the needs of the popular science, I have this comment on the line, the default is http/1.1

Line 5th: Compression level, 1-10, the larger the number of compression, the longer the time, look at the mood casually change it

Line 6th: To compress the file type, the lack of what to fill what on the line, JavaScript has two ways to write, the best is written on it, there is always someone complaining JS file is not compressed, in fact, write a format on the line

Line 7th: With squid and other caching services, on the words will be added to the header "Vary:accept-encoding", I do not need this thing, I look at it against the situation to do it

Line 8th: IE6 is not very friendly to gzip, does not give it gzip

Here's a little bit more about the gzip_proxied configuration parameters:

Syntax:gzip_proxied off |expired | No-cache |no-store | Private |no_last_modified | No_etag |auth | Any ...;
Default: 
gzip_proxied off;


Nginx is enabled as a reverse proxy, turning on or off the results returned by the backend server, if the backend server must return header header containing "Via".

Off
Turn off all proxy result data compression
Expired
Enable compression if the header header contains "Expires" header information
No-cache
Enable compression if the header header contains "Cache-control:no-cache" header information
No-store
Enable compression if the header header contains "Cache-control:no-store" header information
Private
Enable compression if the header header contains "Cache-control:private" header information
No_last_modified
Enable compression if the header header does not contain "last-modified" header information
No_etag
Enable compression if the header header does not contain "ETag" header information
Auth
With compression, if header header contains "Authorization" header information
Any
Enable compression unconditionally

4.: Wq save exit, Reload Nginx

/usr/local/nginx/sbin/nginx-s Reload

5, with Curl Test gzip successfully opened

Curl-i-H "accept-encoding:gzip, deflate" "//www.slyar.com/blog/"

http/1.1 OK
server:nginx/1.0.15
date:sun, Aug 18:13:09 GMT
content-type:text/html -8
connection:keep-alive
x-powered-by:php/5.2.17p1
x-pingback://www.slyar.com/blog/xmlrpc.php
Content-encoding:gzip

Page successfully compressed

Copy Code code as follows:

Curl-i-H "accept-encoding:gzip, deflate" "//www.jb51.net/blog/wp-content/plugins/photonic/include/css/photonic.css"

http/1.1 OK
server:nginx/1.0.15
date:sun, Aug 18:21:25 GMT content-type:text/css
Last-modified:sun Aug 15:17:07 GMT
connection:keep-alive
Expires:mon, Aug-06:21:25 GMT
cache-control:max-age=43200
Content-encoding:gzip

CSS file successfully compressed

Curl-i-H "accept-encoding:gzip, deflate" "//www.slyar.com/blog/wp-includes/js/jquery/jquery.js"

http/1.1 OK
server:nginx/1.0.15
date:sun, Aug 18:21:38 GMT content-type:application/
X-javascript
last-modified:thu 17:42:45 GMT
connection:keep-alive
Expires:mon, Aug 2012 06: 21:38 GMT
cache-control:max-age=43200
content-encoding:gzip

JS file successfully compressed

Copy Code code as follows:

Curl-i-H "accept-encoding:gzip, deflate" "//www.jb51.net/blog/wp-content/uploads/2012/08/2012-08-23_203542.png"

http/1.1 OK
server:nginx/1.0.15
date:sun, Aug 18:22:45 GMT content-type:image/png
Last-modified:thu Aug 13:50:53 GMT
connection:keep-alive
expires:tue, Sep 18:22:45 GMT
Cac he-control:max-age=2592000
Content-encoding:gzip

Picture successfully compressed

Copy Code code as follows:

Curl-i-H "accept-encoding:gzip, deflate" "//www.slyar.com/blog/wp-content/plugins/wp-multicollinks/ Wp-multicollinks.css "

http/1.1 OK
server:nginx/1.0.15
Date:sun, Aug 18:23:27 GMT
Content-type:text/css
content-length:180
Last-modified:sat, May 2009 08:46:15 GMT
Connection:keep-alive
Expires:mon, Aug 06:23:27 GMT
cache-control:max-age=43200
Accept-ranges:bytes

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.