【问题标题】:Nginx cache inactive parameter not workingNginx缓存无效参数不起作用
【发布时间】:2021-07-09 10:34:05
【问题描述】:

我想提供存储在不同服务器上的静态文件。为此,我使用具有以下配置的 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 也工作......但是,proxy_cache_path 中的inactive 参数似乎根本不起作用:10 分钟后没有任何人请求一个文件,该文件没有从缓存中删除,仍然可以在/var/cache/cdn目录中看到。

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

感谢您的帮助,

阿尔贝里希VR

【问题讨论】:

    标签: nginx caching nginx-config nginx-cache


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2018-10-18
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      相关资源
      最近更新 更多