Nginx HttpGzipStaticModule

 

 

    在从磁盘向支持gzip的客户端提供一个文件时,这个模块将会在同样的目录(或者叫位置)中查找同请求文件名相同的、以".gz"格式结尾的文件,这个文件被称为文件的“预压缩格式”,之所以称为“预压缩格式”,是因为Nginx不会去对该文件进行压缩,即使是该文件被访问之后也不会产生".gz"格式的文件,因此需要我们自己压缩。那么这种机制的作用是什么呢?很简单,这么做的原因在于避免每次请求都将对同一个文件进行压缩。

 

ngx_http_gzip_static_modulenginx 0.6.24版本开始提供,但是在默认安装中它是不会被编译安装,因此,在编译时需要指定--with-http_gzip_static_module选项。

 

配置示例

 

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_static

    能:启用该模块。需要注意的是,确定压缩版本和非压缩版本的时间戳要匹配,以便提供最新的内容。

    : gzip_static on|off

默 认 值: gzip_static off

使用环境: http, server, location

 

以下命令参考NginxHttpGzipModule模块:

 

指令名称:gzip_http_version

指令名称:gzip_proxied

指令名称:gzip_disable

指令名称:gzip_vary

 

 

使用实例

 

    在下面的例子中我们先为现有的网页index.html生成一个".gz"格式的文件,即index.html.gz,然后测试访问;在对index.html文件进行修改,然后再访问测试。

 

添加配置

 

  gzip             on;

  gzip_types       text/plain application/xml;

  gzip_static on;

   

 

访问测试

 

    生成index.html文件的另一个格式index.html.gz

 

[root@mfsmaster html]# ls

index.html

[root@mfsmaster html]#cat index.html

Welcome to nginx!

Welcome to nginx!

哈哈!!!

[root@mfsmaster html]# gzip -c index.html  > index.html.gz

[root@mfsmaster html]# ls

index.html  index.html.gz

   

    确定文件的访问时间:

 

[root@mfsmaster html]# stat index.*

  File: ‘index.html’

  Size: 167             Blocks: 8          IO Block: 4096   一般文件

Device: fd00h/64768d    Inode: 5394667     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2011-08-18 16:45:20.339995192 +0800

Modify: 2011-08-18 16:44:16.746662848 +0800

Change: 2011-08-18 16:44:16.746662848 +0800

  File: ‘index.html.gz’

  Size: 151             Blocks: 8          IO Block: 4096   一般文件

Device: fd00h/64768d    Inode: 5394635     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2011-08-18 16:45:20.338995344 +0800

Modify: 2011-08-18 16:45:20.339995192 +0800

Change: 2011-08-18 16:45:20.339995192 +0800

   

    访问该文件:

 

   

 

查看文件的访问时间

 

[root@mfsmaster html]# stat index.*

  File: ‘index.html’

  Size: 167             Blocks: 8          IO Block: 4096   一般文件

Device: fd00h/64768d    Inode: 5394667     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2011-08-18 16:45:20.339995192 +0800

Modify: 2011-08-18 16:44:16.746662848 +0800

Change: 2011-08-18 16:44:16.746662848 +0800

  File: ‘index.html.gz’

  Size: 151             Blocks: 8          IO Block: 4096   一般文件

Device: fd00h/64768d    Inode: 5394635     Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2011-08-18 16:59:01.040229792 +0800

Modify: 2011-08-18 16:45:20.339995192 +0800

Change: 2011-08-18 16:45:20.339995192 +0800

   

    我们比较以下这两个文件的访问时间戳,肯定的说,我们的访问是有‘index.html.gz’文件提供的。

 

    下面将对index.html文件进行修改:

 

[root@mfsmaster html]# vi index.html

 

Welcome to nginx!

Welcome to nginx!

哈哈!!!哈哈!!!

   

    查看文件的访问时间

   

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27043155/viewspace-732982/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27043155/viewspace-732982/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值