1.配置语法
Syntax: proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [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
2.proxy_cache配置语法
Syntax: proxy_cache zone | off;
Default: proxy_cache off;
Context: http, server, location
3.配置语法- 缓存过期周期
Syntax: proxy_cache_valid [code ...] time;
Default: —
Context: http, server, location
4.配置语法-缓存的维度
Syntax: proxy_cache_key string;
Default: proxy_cache_key $scheme$proxy_host$request_uri;
Context: http, server, location
```nginx
upstream imooc {
server 116.62.103.228:8001;
server 116.62.103.228:8002;
server 116.62.103.228:8003;
}
proxy_cache_path /opt/app/cache levels=1:2 keys_zone=imooc_cache:10m max_size=10g inactive=60m use_temp_path=off;
server {
listen 80;
server_name localhost;
location / {
proxy_cache off;
proxy_pass http://imooc;
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";
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
include proxy_params;
}
}
```
5.部分页面不缓存
Syntax: proxy_no_cache string ...;
Default:—
Context:http, server, location
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/test_proxy.access.log main;
if ($request_uri ~ ^/(url3|login/register|password\/reset)){
set $cookie_nochache 1;
}
location / {
proxy_cache off;
proxy_pass http://imooc;
proxy_cache_valid 200 304 12h;
proxy_cache_valid any 10m;
proxy_cache_key $host$uri$is_args$args;
proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;
proxy_no_cache $http_pragma $http_authorization;
add_header Nginx-Cache "$upstream_cache_status";
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
include proxy_params;
}
}
6.大文件分片请求
http_slice_module
Syntax: slice size;
Default: slice 0;
Context:http,server,location