nginx upgrade and configure etag

1, get the compilation parameters of nginx

nginx -V //Get the compilation parameters of nginx -with-http_flv_module --add-module=../nginx-static-etags/ --add-module=../ngx_cache_purge-2.1

 

2, install the extension

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, download and edit the new version of 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/

#Configuration parameters

./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

#Compile (don't make install)

make 

#copy

cd objs

cp nginx nginx.tmp

mv nginx.tmp ../../nginx/sbin/

 

4, modify nginx.conf

location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|xml|txt|flv|swf|mid|doc|cur|xls|pdf|txt|)$ 

{

          FileETag is;

          etag_format "%X%X";

          expires 30d;

        } 

 

5, replace the nginx file and restart

       #Enter the sbin directory of the old nginx

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";

                        }

                }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326359358&siteId=291194637