nginx安装etag模块

来源:互联网 发布:服装设计用什么软件好 编辑:程序博客网 时间:2024/06/08 14:24

nginx 默认有Expires模块,但是却没有Etags 模块.按照Nginx 作者Igor Sysoev的观点,他认为在对静态文件 处理上,还看不出Etags 比Last-Modified的好处.
但是也有人说Nginx 加了Etags 模块会好很多,如这个模块的作者说的那样:

Isee the complete lack of Etag support as an oversight. It’s moregranular than Last-Modified, which is only accurate to the second, andonly measures change along the axis of time; touching a file doesn’tchange it’s content, but would force a cache miss when the cache isbased on nothing but timestamp. Etags ,on the other hand, are content-based identifiers that provide amechanism for confirmation that the content of the file you’re readingis accurate, regardless of inconsequential fiddling or deployment onthe server.

详细内容请访问:http://mikewest.org/2008/11/generating-etags-for-static-content-using-nginx .
下面就主要说说该模块的安装,从这里可以得到源代码 和安装说明:http://wiki.github.com/mikewest/nginx-static-etags
环境是Debian ,我们需要安装git库.一般来说直接执行:'apt-get install git'就可以了,但是这样无法取得SVN上的资料.因为在debian稳定版中去除了git-core库.我们安装就是了,然后nginx 方面,只是在原有配置文件上增加这个模块.要查询之前你配置的参数,可以执行'/usr/local/sbin/nginx -V'.然后在后面增加这个第三方模块.关于第三方模块的使用,可以参考nginx wiki:http://wiki.nginx.org/Nginx3rdPartyModules

$apt-get install git git-core
$curl -O http://sysoev.ru/ nginx /nginx -0.7.63.tar.gz
$tar -zxvf ./nginx -0.7.63.tar.gz
$git-clone git://github.com/mikewest/nginx -static-etags .git /usr/src/nginx -static-etags
$cd nginx -0.7.63/
$./configure --add-mod ule=/usr/src/nginx -static-etags /
...(你原有配置信息)
$make

在这个步骤,出错通常会显示这个信息:
/usr/src/nginx -static-etags /ngx_http_static_etags_module.c:168:2: error: no newline at end of file
make[1]: *** [objs/addon/nginx -static-etags /ngx_http_static_etags_module.o] Error 1
make[1]: Leaving directory `/usr/src/nginx -0.7.63'
make: *** [build] Error 2
出错的原因是这个第三方模块的c文件的最后一行没有用空白行隔开.我们编辑一下这个c文件,在最后一行(也就是168行)增加一个空行就可以了.然后再执行make命令 .
$vi /usr/src/nginx -static-etags /ngx_http_static_etags_module.c
$...
$make
复制到sbin位置就可以了.
$mv /usr/local/sbin/nginx /usr/local/sbin/nginx .old
$cp objs/nginx /usr/local/sbin/
最后重启nginx .
配置方面,一般将所有静态内容都配置Etags 就可以了(参数说明 ).如下:
location ~ .*/.(htm|html|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|xml|txt|flv|swf|mid|doc|cur|xls|pdf|txt|mp3|wma)$ {
expires 7d;
FileETag on;
etag_format "%X%X";

原创粉丝点击