Nginx缓存一个路径

时间:2016-11-04 17:50:17

标签: caching nginx

以下是我的配置

proxy_cache_path /tmp/cache levels=1:2 keys_zone=STATIC:10m inactive=10m  max_size=1g;
server {
        listen 80;
        server_name domain.com www.domain.com;
        client_max_body_size 20M;
        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://domainserver.com:8000;
                proxy_connect_timeout       600;
                proxy_send_timeout          600;
                proxy_read_timeout          600;
                send_timeout                600;
        }
}

我想要缓存所有包含/ ads /的网址

所以如下所示的网址将被缓存

http://domain.com/ads/my-first-ad http://domain.com/ads/my-seconnd-ad

1 个答案:

答案 0 :(得分:0)

我添加了以下内容并且有效

location /ads/ {
        proxy_pass http://domainserver.com:8000;
        proxy_cache STATIC;
        proxy_cache_key "$proxy_host$uri$is_args$args";
        proxy_cache_valid 30d;
        proxy_cache_valid any 10s;
        proxy_cache_lock on;
        proxy_cache_use_stale error invalid_header timeout updating;
        proxy_http_version 1.1;
        expires 30d;
}