1

我想提供存储在不同服务器上的静态文件。为此,我使用具有以下配置的 Nginx 缓存。

Nginx 缓存配置:

proxy_cache_path   /var/cache/cdn levels=1:2 keys_zone=cdn:64m max_size=20g inactive=10m use_temp_path=off;

服务配置:

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name <server-name>;

    ssl_certificate <fullchain>;
    ssl_certificate_key <key>;

    location / {
        # Activate caching
        proxy_cache cdn;

        # Cache becomes stale after 1 minute
        proxy_cache_valid 1m;

        # Download stale data only if it has been modified on origin 
        proxy_cache_revalidate on;

        # Use stale file origin is unaccessible 
        proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;

        # If multiple clients get a MISS for the same file, 
        # the file is downloaded form Origin only once
        proxy_cache_lock on;

        # Filesystem key
        proxy_cache_key $uri$is_args$args;          

        # Gives the status of the file returned
        # MISS, BYPASS, EXPIRED, STALE, UPDATING, REVALIDATED, HIT
        add_header X-Cache-Status $upstream_cache_status;

        # Origin server address
        proxy_pass <server origin>;
    }
}

server{
    listen 80;
    listen [::]:80;
    server_name <server-name>;

    if ($host = <server-name>) {
        return 301 https://$host$request_uri;
    }
}

此设置全局工作正常:文件已交付,重新验证工作,proxy_cache_valid 也工作......但是,inactive参数 inproxy_cache_path似乎根本不起作用:在没有任何人请求文件的情况下 10 分钟后,所述文件未被删除缓存并且仍然可以在 /var/cache/cdn 目录中看到。

这是正常的吗?我搞砸了我的配置吗?

感谢您的帮助,

AlberichVR

4

1 回答 1

0

经过网上大量研究和反复试验,我发现了问题:我使用的缓存文件夹的权限为700。将它们更改为777后,问题自行解决。

于 2021-04-14T19:12:06.473 回答