ch04 proxy_cache

4.1 proxy_cache_path

proxy_cache_path /data/cache levels=1:2 keys_zone=my_cache:100m max_size=500m inactive=3h;
server {
	location /pp {
		#在客户端收到的响应报头中验证缓存功能
		add_header X-Cache $upstream_cache_status via $server_addr;
		
		#代理至后端时,使用keep-alive
		proxy_http_version 1.1;
		proxy_set_header Connection "keep-alive";
		#同时在后端服务器中LogFormat中启用%{X-Forwarded-For}i
		#来记录真实client地址
		proxy_set_header X-Forwarded-For $remote_addr;
		
		proxy_pass http://websrv/remote;
		proxy_cache my_cache;
		#没有这行时,X-Cache一直是MISS 
		proxy_cache_valid 200 10s;
		#为哪些请求方法启用缓存功能
		proxy_cache_methods GET | HEAD | POST ...; 
		#设置缓存key,将用户私有信息用于键可以
		#避免将用户的私有信息返回给其它用户
		proxy_cache_key $remote_addr$request_uri;
	}
}

4.2 proxy_cache_key

proxy_cache_key "$host$request_uri $cookie_user";

The default proxy_cache_key, which will fit most use cases, is

"\$scheme\$proxy_host\$request_uri"

4.3 proxy_cache_bypass

set $arg_cache 1;
proxy_cache_bypass $arg_nocache;


proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;

按书上说的

proxy_cache_bypass $http_cache_bypass;

The configuration tells NGINX to bypass the cache if the HTTP
request header named cache_bypass is set to any value that is not 0.
没有用

4.4

location ~* \.(css|js)$ {
	expires 1y;
	add_header Cache-Control "public";
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值