nginx的配置缓存


worker_processes  2;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

	sendfile        on;
        #设置上传的文件大小,默认是1M,现在允许8M
	client_max_body_size 8M;
	client_body_buffer_size 128k;
    keepalive_timeout  65;
	
	proxy_cache_path /cache/cache levels=1:2 keys_zone=cache_one:50m inactive=20m max_size=30g;
	proxy_connect_timeout   5;
	proxy_send_timeout      5;
	proxy_read_timeout      5;
	#配置轮询,当8080down后就不在访问
	#如果8080也关掉以后,那么会访问backup备份的.这里要注意的是timeout这三个变量
	#因为之前没有加上,就访问了很久以后才会backup
    upstream localhost { 
	    #server localhost:7070 down;
		server localhost:8080;
		server localhost:9090 backup;
	}	
    server {
        listen       80;
        server_name  localhost;

        #access_log  logs/host.access.log  main;
		
		#配置项目的路径
		location /jfinal_demo {
			proxy_pass http://localhost/jfinal_demo;
		}
		#配置html和jsp的路径
		location ~.*\.(htm|html|jsp)$ {
			proxy_pass http://localhost;
		}
		#配置css jpg的缓存
        location ~.*\.(gif|jpg|png|bmp|swf|js|css)$ {
			 proxy_redirect off;
			 proxy_set_header Host $host;
			 proxy_cache cache_one;
			 proxy_cache_valid 200 302 24h;
			 proxy_cache_valid 301 30d;
			 proxy_cache_valid any 5m;
			 expires 90d;
			 proxy_pass http://localhost;
        }
    }

}

你可能感兴趣的:(nginx)