RSS
 

nginx+squid+gzip压缩

31 Mar

现象:nginx0.7.26 squid 2.7.9,发现压缩的页面失效,但如果跳过squid,页面压缩是有效的。

Google了一下,主要是两篇文章,两种说法:

1.说是修改squid 的 “broken_vary_encoding all”

由于文章乱转载,一时不能确定出处,所以出处可能是:

http://zys.8800.org/index.php/archives/282

2. nginx默认是使用的动态的gzip压缩,而squid2系列还不支持,所以要重新编译nginx (./configure –with-http_gzip_static_module)。

出处:http://bbs.chinaunix.net/viewthread.php?tid=1329820

有趣的是:这个原文出处的指出的原文是:http://zys.8800.org/?p=267 

但已经404错误了。

经过我的测试:第2种说法是成立的,第1种不成立,但为什么原作者却保留了一篇错误的文章,把正确的反而删了?

如果这篇文章到这里就结束了,肯定会被各位看官扔鸡蛋了,一点原创性的东西都没有,就来骗稿费(真没有稿费…)

所以我对原文给出的nginx配置做了一些优化和测试:

下面是原文给出的nginx配置:

    gzip             on
    gzip_static on;
    gzip_http_version   1.0;
    gzip_proxied        any;
    gzip_disable        "MSIE [1-6]\.";
    gzip_comp_level     9;

  1. gzip on后面少一个”;”
  2. 经过测试IE6是可以完美支持gzip的,无论是在http 1.0还是1.1的请求下,所以把IE6目前这个最广泛的浏览器排除在外,实在不解,所以我改成:gzip_disable        "MSIE [1-5]\.";
  3. 增加 gzip_types 因为nginx默认只对"text/html“压缩,但同样是文本文件的xml,css,js也是需要压缩的,所以增加这一行

    gzip_types       text/plain application/xml  application/x-javascript text/css ;  

             详情可以参考: http://wiki.nginx.org/NginxHttpGzipModule

  4. 我对gzip_comp_level进行了测试,分别从1到9,9虽然压缩比率是   最大的,但如果不适当,消耗过多的服务器资源,也是适得其反哦。我使用了一个大概是103KB的文本文件,分别使用1-9进行测试

 

压缩前 压缩比率 压缩后
103KB 1 27KB
103KB 2 26KB
103KB 3 26KB
103KB 4 24KB
103KB 5 24KB
103KB 9 23KB

所以我选择了压缩比为4 。

 
 

Tags: , ,

  1. Interactive Buddy

    December 6, 2011 at 7:55 pm

    Awesome website…

    [...]the time to read or visit the content or sites we have linked to below the[...]……

     
  2. Real Estate News

    December 15, 2011 at 9:20 pm

    Great website…

    [...]we like to honor many other internet sites on the web, even if they aren’t linked to us, by linking to them. Under are some webpages worth checking out[...]……

     
  3. my blog

    December 16, 2011 at 3:30 pm

    Gems form the internet…

    [...]very few websites that happen to be detailed below, from our point of view are undoubtedly well worth checking out[...]……

     
  4. Rhinoplasty Doctors

    December 17, 2011 at 10:10 am

    Recent Blogroll Additions……

    [...]usually posts some very interesting stuff like this. If you’re new to this site[...]……

     
  5. Build Hydro Electric Generator

    December 18, 2011 at 8:04 pm

    Superb website…

    [...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]……

     

Leave a Reply

 

 
 
viagraatlantic drugs