- 语法
Syntax: proxy_cache_path path [levels=levels] [use_temp_path=off|on] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=numers] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time][loader_threshold=time] [purger=on|off][purger_files=number] [purger_sleep=time] [purger_threshold=time] Default:-- Context:http
##例:/etc/nginx/conf.d/default.conf upstream test_upstream { server localhost:8001; server localhost:8002; server localhost:8003; } proxy_cache_path /opt/app/cache levels=1:2 keys_zone=test_cache:10m max_size=10g inactive=60m use_temp_path=off; server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; location / { proxy_pass http://test_upstream; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_cache off; proxy_cache_valid 200 304 12h; proxy_cache_valid any 10m; proxy_cache_key $host$uri$is_args$args; add_header Nginx-Cache "$upstream_cache_status"; } ... ...
-
补充:
-
如何清理指定缓存?
1. rm -rf 缓存目录内容
2. 第三方扩展模块 ngx_cache_purge -
如何让部分页面不缓存
Syntax: proxy_no_cache string ...; Default: -- Context:http,server,location
##例:/etc/nginx/conf.d/default.conf upstream test_upstream { server localhost:8001; server localhost:8002; server localhost:8003; } proxy_cache_path /opt/app/cache levels=1:2 keys_zone=test_cache:10m max_size=10g inactive=60m use_temp_path=off; server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/test_proxy.access.log main; if ($request_uri ~ ^/index){ ##匹配以index开头的请求 set $cookie_nocache 1; } location / { proxy_pass http://test_upstream; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_cache test_cache; proxy_cache_valid 200 304 12h; proxy_cache_valid any 10m; proxy_cache_key $host$uri$is_args$args; proxy_no_cache $cookie_nocache; add_header Nginx-Cache "$upstream_cache_status"; }
-
大文件分片请求
Syntax:slice size; Default: slice 0; Context:http,server,location