nginx图片服务器配置

worker_processes  1;  
  
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid  /usr/local/nginx-0.8.32/nginx.pid;  
  
events {      
    worker_connections  1024;  
}  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
  
    charset  utf-8;            
    server_names_hash_bucket_size 128;     
    client_header_buffer_size 32k;     
    large_client_header_buffers 4 32k;     
    client_max_body_size 300m;            
    sendfile on;     
    tcp_nopush     on;  
  
    keepalive_timeout 60;  
    tcp_nodelay on;      
    client_body_buffer_size  512k;     
    proxy_connect_timeout    5;     
    proxy_read_timeout       60;     
    proxy_send_timeout       5;     
    proxy_buffer_size        16k;     
    proxy_buffers            4 64k;     
    proxy_busy_buffers_size 128k;     
    proxy_temp_file_write_size 128k;      
      
    gzip on;     
    gzip_min_length  1k;     
    gzip_buffers 4 16k;     
    gzip_http_version 1.1;     
    gzip_comp_level 2;     
    gzip_types text/plain application/x-javascript text/css application/xml;     
    gzip_vary on;  
  
    #注:images_temp和images_cache指定的路径必须在同一分区  
    proxy_temp_path  pictem;  
    #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。  
    proxy_cache_path  piccache  levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=30g;    
    server {  
        listen       8081;  
        server_name  182.180.57.3;  
        location / {  
                proxy_cache cache_one;  
                #对不同的HTTP状态码设置不同的缓存时间  
                proxy_cache_valid  200 304 12h;  
                #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内  
                proxy_cache_key $host$uri$is_args$args;  
                proxy_set_header Host  $host;  
                proxy_set_header X-Forwarded-For  $remote_addr;  
                proxy_pass http://182.180.57.3:8080;
                expires      1d;  
                }
        #扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存。  
        location ~ .*\.(php|jsp|cgi)?$ {  
                proxy_set_header Host  $host;  
                proxy_set_header X-Forwarded-For  $remote_addr;  
                proxy_pass http://182.180.57.3:8080;  
        }
         #用于清除缓存,假设一个URL为http://192.168.8.42/test.txt,通过访问http://192.168.8.42/purge/test.txt就可以清除该URL的缓存。  
        location ~/purge(/.*) {  
            #设置只允许指定的IP或IP段才可以清除URL缓存。  
            allow       127.0.0.1;               
            deny    all;
            #貌似window版本的没有这个模块,因此清理缓存有问题
            #proxy_cache_purge cache_one $host$1$is_args$args;                        
        }           
        access_log  off;                 
    }  
  
    #真实的图片服务器
    server{
        listen 8080;
        server_name 127.0.0.1; 
        location / { 
            root C:/pic;            
        }
    }
} 

 

posted @ 2015-12-15 16:17  wujf  阅读(326)  评论(0编辑  收藏  举报