开启Nginx的gzip压缩功能

默认情况下,Nginx的gzip压缩是关闭的。同时,Nginx默认只对text/html进行压缩。

开启gzip的指令如下:

gzip on; 
gzip_min_length  1000; 
gzip_buffers     4 8k; 
gzip_comp_level 6;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6].";
gzip_types text/plain application/x-javascript text/css text/javascript;

1. 其中的gzip_http_version设置,它的默认值是1.1,就是说对HTTP/1.1协议的请求才会进行gzip压缩。

如果我们使用了proxy_pass进行反向代理,那么nginx和后端的upstream server之间是用HTTP/1.0协议通信的。

This module makes it possible to transfer requests to another server.

It is an HTTP/1.0 proxy without the ability for keep-alive requests yet. (As a result, backend connections are created and destroyed on every request.) Nginx talks HTTP/1.1 to the browser and HTTP/1.0 to the backend server. As such it handles keep-alive to the browser.

如果我们使用nginx通过反向代理做Cache Server,而且前端的nginx没有开启gzip,同时,后端的nginx上没有设置gzip_http_version为1.0,那么Cache的url将不会进行gzip压缩。

2. gzip_disable的设置是禁用IE6的gzip压缩,因为IE6的某些版本对gzip的压缩支持很不好,会造成页面的假死。为了确保其它的IE6版本不出问题,所以就加上了gzip_disable的设置。

猜你喜欢

转载自eric-gao.iteye.com/blog/866625
今日推荐