nginx静态压缩(ngx_http_gzip_static_module)

凉白开 Nginx226,9112字数 972阅读3分14秒阅读模式

nginx实现静态压缩这种做法其实就像apache gzip压缩了,这种压缩是我们常见的一些事情了,下面我来介绍一些做法。

在搭建squid网页加速的时候,对于大的css 或者js要进行压缩,然后再进行缓存,这样能够提高减小下载量提高页面响应速度。如果你用的是squid 3.0以前的版本并且用的是 ngnix server的话可能会碰到如下问题: 不用squid直接打开页面则客户端返回的是压缩的状态,如果启用squid加速会发现下载下来的页面不是压缩状态。这里面主要是没有启动ngnix 的静态缓存模块(ngx_http_gzip_static_module)导致。文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/

打开静态缓存问题就解决了文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/

nginx编译选项

 ./configure --with-http_gzip_static_module

配置nginx

gzip_static on;
gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6] .";
gzip_vary on;
#找不到预压缩文件,进行动态压缩
gzip on;
gzip_min_length 1000;
gzip_buffers 4 16k;
gzip_comp_level 5;
gzip_types text/plain application/x-javascript text/css application/xml;
#gzip公共配置
gzip_http_version 1.1
gzip_proxied expired no-cache no-store private auth;

gzip_vary on说明

对于支持gzip的请求反向代理缓存服务器将返回gzip内容,不支持gzip的客户端返回原始内容。文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/

其他说明

  • gzip_static配置优先级高于gzip
  • 开启nginx_static后,对于任何文件都会先查找是否有对应的gz文件
  • gzip_types设置对gzip_static无效

 文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/

转自:http://www.php100.com/html/program/nginx/2013/0905/5548.html文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/ 文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
凉白开
  • 本文由 发表于 26/05/2015 08:42:21
  • 转载请务必保留本文链接:https://www.ttlsa.com/nginx/nginx-ngx_http_gzip_static_module/
  • gzip
  • nginx gzip
  • nginx压缩
  • ngx_http_gzip_static_module
评论  2  访客  2
    • 运维生存时间网友
      运维生存时间网友 9

      WAWEDADA但是当时的

      • 匿名
        匿名 9

        WAWEDADA但是当时的

      评论已关闭!