nginx 升级并配置etag
1,获取nginx的编译参数
nginx -V //获取nginx的编译参数 -with-http_flv_module --add-module=../nginx-static-etags/ --add-module=../ngx_cache_purge-2.1
2,安装扩展
a,nginx-static-etags
git clone git://github.com/mikewest/nginx-static-etags.git ./nginx-static-etags
b,ngx_cache_purge-2.1
git clone https://github.com/FRiCKLE/ngx_cache_purge.git ./ngx_cache_purge-2.1
3,下载并编辑新版nginx
wget http://nginx.org/download/nginx-1.5.8.tar.gz
tar -xvf nginx-1.5.8.tar.gz
cd nginx-1.5.8/
#配置参数
./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/src/openssl-0.9.8-stable-SNAP-20130403 --with-pcre=/usr/local/src/pcre-8.32 --with-debug --with-http_gzip_static_module --with-http_sub_module --with-http_stub_status_module --without-http_map_module --without-http_geo_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_flv_module --add-module=../nginx-static-etags/ --add-module=../ngx_cache_purge-2.1
#编译 (不要make install)
make
#拷贝
cd objs
cp nginx nginx.tmp
mv nginx.tmp ../../nginx/sbin/
4,修改nginx.conf
location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|xml|txt|flv|swf|mid|doc|cur|xls|pdf|txt|)$
{
FileETag on;
etag_format "%X%X";
expires 30d;
}
5,替换nginx文件并重启
#进入老nginx的sbin目录
cp nginx nginx.bak
rm -rf /usr/local/nginx/sbin/nginx && mv /usr/local/nginx/sbin/nginx.tmp /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` #让nginx把nginx.pid改成nginx.pid.oldbin 并启动新的nginx
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
6,禁用缓存配置
location ~ index\.html$
{
add_header Cache-Control "no-store";
expires -1;
etag off;
}
7,开发环境起用
location ~ \.php$
{
fastcgi_pass unix:/dev/shm/php.sock;
fastcgi_index index.php;
include fcgi.conf;
set $a 0;
if ( $server_name ~ .*\.dev\.com ) {
set $a 1;
}
if ( $http_referer ~ /local\.dev\.com/ ){
set $a 1$a;
}
if ($document_uri ~ '.*(\/apiv1\/|\/apiv5\/).*'){
add_header Access-Control-Allow-Origin "*";
}
if ( $a = 11){
add_header Access-Control-Allow-Origin "http://local.dev.com";
add_header Access-Control-Allow-Credentials "true";
}
}