nginx默认有Expires模块,但是却没有Etags模块.按照Nginx作者Igor Sysoev的观点,他认为在对静态文件处理上,还看不出Etags比Last-Modified的好处.
但是也有人说Nginx加了Etags模块会好很多,如这个模块的作者说的那样:
下面就主要说说该模块的安装
需要安装git库,然后nginx 方面,只是在原有配置文件上增加这个模块.要查询之前你配置的参数,可以执行'/usr/local/sbin/nginx -V'.然后在后面增加这个第三方模块
安装过程:
#cd /var/tmp
#wget http://wiki.github.com/mikewest/nginx-static-etags
#yum install git git-core
#wget http://sysoev.ru/ nginx /nginx -0.7.63.tar.gz
#tar zxvf nginx -0.7.63.tar.gz
#cd !$
#./configure (其他参数) --add-mod ule=/var/tmp/nginx -static-etags
#make && make install
配置方面,一般将所有静态内容都配置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";
}
常见错误:
1、/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
2、core/ngx_regex.o: In function `ngx_pcre_free_studies':
nginx-1.2.1/src/core/ngx_regex.c:307: undefined reference to `pcre_free_study'
指定正则库:--with-pcre --with-pcre-jit &&
Make && make install
若还报错:由于pcre正则库的错误,查看prce的版本
#rpm -qa|grep prce
pcre-static-7.8-3.1.el6.x86_64
pcre-7.8-3.1.el6.x86_64
pcre-devel-7.8-3.1.el6.x86_64
版本要一致,否则重新安装
Make && make install
联系客服