NutzCN Logo
问答 nginx启用缓存,这样配置对吗
发布于 2819天前 作者 ecoolper 2088 次浏览 复制 上一个帖子 下一个帖子
标签:
	#缓存配置  表示10天没有被访问的内容自动清除,硬盘最大缓存空间为2GB,超过这个大学将清除最近最少使用的数据。
	proxy_cache_path /nginx/cache levels=1:2 keys_zone=cache_one:50m inactive=10d max_size=2g;
	proxy_temp_path /nginx/cache/temp;
		location /x5/ {
			#缓存配置
			proxy_cache cache_one;
			proxy_cache_lock on;
            proxy_cache_valid 200 304 12h;
            #proxy_cache_valid any 10s;
			proxy_cache_use_stale updating;
			proxy_cache_key $host$uri$is_args$args;
			
			proxy_pass   http://127.0.0.1:8080;
			proxy_set_header  X-Real-IP  $remote_addr;
			proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
			proxy_set_header  Host $http_host;
			proxy_redirect 	 http:// https://;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection $http_connection; 			
        }
1 回复
proxy_temp_path   /proxy_temp;
proxy_cache_path  /proxy_cache levels=1:2 keys_zone=cache_one:100m inactive=2d max_size=2g;

server {
	listen 80;
	listen 443 ssl;
	if ( $scheme = "http" ) {
            rewrite ^(.*) https://$host$1;
	}
	server_name nutzwk.wizzer.cn;
	root "/java/work/nutzwk";	
	ssl_certificate /java/work/nutzwk.pem;
	ssl_certificate_key /java/work/nutzwk.key;
	ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
	add_header "X-UA-Compatible" "IE=Edge, chrome=1";
	location / {
		proxy_pass http://127.0.0.1:9091;
		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 ~ \.(jpg|png|jpeg|gif)$  {
	    expires 30d;
	    proxy_pass  http://127.0.0.1:9091;
            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;

            proxy_cache cache_one;
            proxy_ignore_headers Cache-Control;
            add_header Nginx-Cache $upstream_cache_status;
            proxy_cache_valid  200 304 301 302 8h;
            proxy_cache_valid 404 1m;
            proxy_cache_valid  any 2d;
            proxy_cache_key $host$uri$is_args$args;
	}

	location ~ \.(js|css)$  {
	    expires 2h;
	    proxy_pass  http://127.0.0.1:9091;
            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;

            proxy_cache cache_one;
            proxy_ignore_headers Cache-Control;
            add_header Nginx-Cache $upstream_cache_status;
            proxy_cache_valid  200 304 301 302 8h;
            proxy_cache_valid 404 1m;
            proxy_cache_valid  any 2d;
            proxy_cache_key $host$uri$is_args$args;
	}
}
添加回复
请先登陆
回到顶部