nginx利用proxy_cache来缓存文件

user  zhangy users;
worker_processes 10;
error_log  /var/vlogs/nginx_error.log  crit;
pid        /var/vlogs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
 use epoll;
 worker_connections 65535;
}
http
{
 include       mime.types;
 default_type  application/octet-stream;
 #charset  gb2312;
 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 client_max_body_size 8m;
 sendfile on;
 tcp_nopush     on;
 keepalive_timeout 60;

 tcp_nodelay on;

 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
//============
 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;
 proxy_temp_path   /usr/local/nginx/proxy_temp;
/*levels设置目录层次
keys_zone设置缓存名字和共享内存大小
inactive在指定时间内没人访问则被删除在这里是1天
max_size最大缓存空间*/
proxy_cache_path /usr/local/nginx/proxy_cache levels=1:2 keys_zone=content:20m inactive=1d max_size=100m;
//============等号中间要加的,关键只要加上proxy_cache_path

 gzip on;
 gzip_min_length  1k;
 gzip_buffers     4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types       text/plain application/x-javascript text/css application/xml;
 gzip_vary on;

 upstream myselfxtajmd {
 server 127.0.0.1:10002;
 server 127.0.0.1:10001 weight=5;
 }

 server
 {
 listen       10000;
 server_name  localhost;
 index index.html index.htm index.php;
 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
 '$status $body_bytes_sent "$http_referer" '
 '"$http_user_agent" $http_x_forwarded_for';
 access_log  /var/log/test.log  access;

 location /
 {
 proxy_cache content; //根keys_zone后的内容对应
 proxy_cache_valid  200 304 301 302 10d;   //哪些状态缓存多长时间
 proxy_cache_valid  any 1d;    //其他的缓存多长时间
 proxy_cache_key $host$uri$is_args$args;   //通过key来hash,定义KEY的值

 proxy_pass http://myselfxtajmd;
 proxy_redirect                      off;
 proxy_set_header   Host             $host;
 proxy_set_header   X-Real-IP        $remote_addr;
 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 }

//动态的放过
 location ~ .*\.(php|jsp|cgi)?$
 {
 proxy_set_header Host  $host;
 proxy_set_header X-Forwarded-For  $remote_addr;
 proxy_pass http://myselfxtajmd;
 }
 }
}

 

你可能感兴趣的:(cache)