一、第一步定义一个缓存目录设置目录结构
 在 http 模块下定义(keys_zone = 缓存区名:后面是缓存区大小 inactive 不活跃的文件多久清理 max_size 缓存区所占磁盘的上限 use_temp_path 默认关闭(有需要自己百度))
proxy_cache_path /path/your_cache_dir levels = 1:2 keys_zone=your_cache_name:10g inactive=1h max_size=20g use_temp_path=off; 
二、开启缓存
 在 http、server、location 中开启代理缓存
 举例在location中开启(将图片jscsshtml等放入缓存)
server {listen 8099;   #缓存端口或者缓存域名root /www/wwwroot/static/;index index.html;location ~*.\.(png|jpg|css|html)$ {expires  30m;				#缓存过期时间在浏览器的缓存时间proxy_pass http://localhost:8100;		# 代理地址非缓存文件的访问地址,***必须加这个否则生成不来缓存这个***proxy_cache your_cache_name;    	#proxy_cache_path中定义的名字proxy_cache_valid 200 10m;				#把状态值为200的缓存10分钟proxy_cache_valid any 5m; 				#把状态值除来200的缓存5分钟proxy_cache_key "$host$request_uri"; 	#默认keyproxy_cache_revalidate on;				#是否开启验证缓存的有效性关闭则缓存数据有变化依然请求缓存 开启则会请求新的proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;				#当后台出现错误时跳过add_header X-Proxy-Cache $upstream_cache_status;			#在头文件新增一个X-Proxy-Cache(自定义)验证缓存是否命中 Hit命中 miss 没有命中}
}server {listen 8100; 		#正式的地址root /www/wwwroot/static/;index index.html; # 其他配置...
}
注意事项
 nginx 缓存叫代理缓存 应该是有两台以上的服务器。如果只有一台加不同的域名或者端口做区分。把后台服务器和缓存服务分开
缓存没有生成
 1、文件夹是否有权限
 2、是否设置了proxy_pass(只有走代理才会生成缓存)