`

nignx + ngx_cache_purge 配置

 
阅读更多

1、下载ngx_cache_purge: http://labs.frickle.com/nginx_ngx_cache_purge/

2、下载nginx :http://nginx.org/download/nginx-1.4.1.tar.gz

3、下载zlib :http://prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz?download

4、下载pcre :http://sourceforge.net/projects/pcre/files/pcre/8.33/pcre-8.33.tar.gz/download

5、解压
     将上面所有包解压到同一目录。
6、安装

    cd /work/
     进入解压后的nginx-1.4.1目录,执行。
  ./configure --prefix=/work/nginx --with-pcre=/works/pcre-8.33 --with-zlib=/work/zlib-1.2.7 --add-module=/work/ngx_cache_purge-2.1

 make && make install

 

cd /work/nginx
mdkir proxy_temp_path

mdkir proxy_cache_path


7、配置 nginx.conf

   

#user  nobody;  
worker_processes  1;  
  
#error_log  logs/error.log;  
#error_log  logs/error.log  notice;  
#error_log  logs/error.log  info;  
  
#pid        logs/nginx.pid;  
  
  
events {  
    use epoll;  
    worker_connections  51200;  
}  
  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
  
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
    #                  '$status $body_bytes_sent "$http_referer" '  
    #                  '"$http_user_agent" "$http_x_forwarded_for"';  
  
    #access_log  logs/access.log  main;  
  
    sendfile        on;  
    tcp_nopush     on;  
    server_names_hash_bucket_size 64;  
    keepalive_timeout  65;  
    tcp_nodelay on;  
    client_header_timeout  3m;  
    client_body_timeout    3m;  
    send_timeout           3m;  
     
    connection_pool_size        512;  
    client_header_buffer_size    1k;  
    #large_client_header_buffers    4 2k;  
    request_pool_size        4k;  
    output_buffers   4 32k;  
    postpone_output  1460;  
    client_max_body_size       10m;  
    client_body_buffer_size    256k;  
    proxy_temp_path /work/nginx/proxy_temp_path;     
    proxy_cache_path /work/nginx/proxy_cache_path levels=1:2 keys_zone=ngx_cache:200m inactive=1d max_size=30g;  
    fastcgi_connect_timeout 200;  
    fastcgi_send_timeout 200;  
    fastcgi_read_timeout 200;  
    fastcgi_buffer_size 128k;  
    fastcgi_buffers 4 128k;  
    fastcgi_busy_buffers_size 128k;  
    fastcgi_temp_file_write_size 128k;  
    fastcgi_temp_path /dev/shm;  
  
    gzip  on;  
    gzip_comp_level 9;  
    gzip_min_length  1k;  
    gzip_buffers     4 8k;  
    gzip_http_version 1.1;  
    gzip_types       text/plain application/x-javascript text/css application/xml;  
    gzip_vary on;  
  
    upstream my_server_pool{  
      server  100.22.160.67:8080;  
  
    }  
  
    server {  
        listen       80;  
        server_name  localhost;  
  
        #charset koi8-r;  
  
        #access_log  logs/host.access.log  main;  
  
                  
        location ~ /purge(/.*){  
               proxy_cache_purge ngx_cache $host$1$is_args$args;  
               error_page 405 =200 /purge$1;  
         }  
         if ( $request_method = "PURGE" ) {  
            rewrite ^(.*)$ /purge$1 last;  
         }  
  
  
        location / {  
            proxy_set_header Host $host;  
            proxy_set_header X-Forwarded-For $remote_addr;  
            #proxy_pass http://my_server_pool;  
            root ../html/;
        }  
        
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {  
            proxy_set_header Host $host;  
            proxy_set_header X-Forwarded-For $remote_addr;  
            proxy_cache ngx_cache;  
            proxy_cache_valid 200 304 12h;  
            proxy_cache_valid 301 302 1m;      
            proxy_cache_valid any 1m;  
            add_header NGX_CACHE $upstream_cache_status;   
            proxy_cache_key $host$uri$is_args$args;       
            proxy_pass http://my_server_pool;  
   
         }  
           
  
    }  
  
  
} 

 


8、启动nginx sbin/nginx

#用于清除缓存,假设一个URL为http://xxx.test.com/test.gif,通过访问
    #http://xxx.test.com/purge/test.gif可以清楚该url的缓存

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics