Nginx 预配置缓存

<!-- wp:shortcode -->
#nginx设定获取url中请求包含nc参数的进行预先配置缓存,开发人员根据需求自定义缓存级别,缓存配置为nginx和CDN两层生效。
#接口缓存 
 location ~ /loadSeat.jsonp {
	# access_log /opt/logs/nginx/ticket.acc1.log;
	# error_log /opt/logs/nginx/ticket.err1.log ;

		add_header  Web-Tag "/loadSeat";		
		#添加nc参数,用于缓冲ajax数据
		add_header  arg_nc "$arg_nc";
		add_header  arg_type "$arg_type";
		if ( $arg_type = "ck" ){                              #不做缓存
			#access_log /opt/logs/nginx/ticket.acc2.log;
                        proxy_pass  http://ticket;
			break;
                }
		if ( $arg_type != "ck" ){					#默认15s,默认规则要写在最上面
			proxy_pass  http://127.0.0.1:90;
		}
		if ( $arg_nc = 30 ){					#30S
			proxy_pass  http://127.0.0.1:81;
		}
		if ( $arg_nc = 60 ){					#1m
			proxy_pass  http://127.0.0.1:82;
		}
		if ( $arg_nc = 180 ){					#3m
			proxy_pass  http://127.0.0.1:83;
		}
		if ( $arg_nc = 300 ){					#5m
			proxy_pass  http://127.0.0.1:84;
		}
		if ( $arg_nc = 600 ){					#10m
			proxy_pass  http://127.0.0.1:85;
		}
	#	proxy_pass http://ticket;
    }

[root@WEB conf.d]# cat nc.conf 
server  {										#30s
	listen       81;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 30s;
		add_header  Web-Tag "81";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 30s;
	}
}

server  {										#1m
	listen       82;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 60s;
		add_header  Web-Tag "82";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 1m;
	}
}

server  {										#3m
	listen       83;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 180s;
		add_header  Web-Tag "83";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 3m;
	}
}

server  {										#5m
	listen       84;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 300s;
		add_header  Web-Tag "84";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 5m;
	}
}

server  {										#10m
	listen       85;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 600s;
		add_header  Web-Tag "85";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 10m;
	}
}
server  {										#15s
	listen       90;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 15s;
		add_header  Web-Tag "90";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 15s;
	}
}
<!-- /wp:shortcode -->

<!-- wp:shortcode -->
#nginx设定获取url中请求包含nc参数的进行预先配置缓存,开发人员根据需求自定义缓存级别,缓存配置为nginx和CDN两层生效。
#接口缓存 
 location ~ /loadSeat.jsonp {
	# access_log /opt/logs/nginx/ticket.acc1.log;
	# error_log /opt/logs/nginx/ticket.err1.log ;

		add_header  Web-Tag "/loadSeat";		
		#添加nc参数,用于缓冲ajax数据
		add_header  arg_nc "$arg_nc";
		add_header  arg_type "$arg_type";
		if ( $arg_type = "ck" ){                              #不做缓存
			#access_log /opt/logs/nginx/ticket.acc2.log;
                        proxy_pass  http://ticket;
			break;
                }
		if ( $arg_type != "ck" ){					#默认15s,默认规则要写在最上面
			proxy_pass  http://127.0.0.1:90;
		}
		if ( $arg_nc = 30 ){					#30S
			proxy_pass  http://127.0.0.1:81;
		}
		if ( $arg_nc = 60 ){					#1m
			proxy_pass  http://127.0.0.1:82;
		}
		if ( $arg_nc = 180 ){					#3m
			proxy_pass  http://127.0.0.1:83;
		}
		if ( $arg_nc = 300 ){					#5m
			proxy_pass  http://127.0.0.1:84;
		}
		if ( $arg_nc = 600 ){					#10m
			proxy_pass  http://127.0.0.1:85;
		}
	#	proxy_pass http://ticket;
    }

[root@WEB conf.d]# cat nc.conf 
server  {										#30s
	listen       81;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 30s;
		add_header  Web-Tag "81";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 30s;
	}
}

server  {										#1m
	listen       82;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 60s;
		add_header  Web-Tag "82";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 1m;
	}
}

server  {										#3m
	listen       83;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 180s;
		add_header  Web-Tag "83";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 3m;
	}
}

server  {										#5m
	listen       84;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 300s;
		add_header  Web-Tag "84";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 5m;
	}
}

server  {										#10m
	listen       85;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 600s;
		add_header  Web-Tag "85";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 10m;
	}
}
server  {										#15s
	listen       90;
	server_name  127.0.0.1;
	location /  {
		proxy_pass  http://ticket;
		proxy_cache cache_one;
		proxy_cache_valid 200 302 15s;
		add_header  Web-Tag "90";	
		add_header  Web-Cache "$upstream_cache_status";
		expires 15s;
	}
}
<!-- /wp:shortcode -->

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值