1

I want to serve static files stored on a different server. For that I use Nginx cache with the following configuration.

Nginx cache conf:

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

Service conf:

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;
    }
}

This setup globally works fine: files are delivered, the revalidate works, the proxy_cache_valid works too... However, the inactive parameter in proxy_cache_path doesn't seem to function at all: after 10 minutes without anyone requesting a file, said file is not deleted from cache and can still be seen in the /var/cache/cdn directory.

Is this normal ? Did I mess my configuation up ?

Thanks for your Help,

AlberichVR

AlberichVR
  • 11
  • 1

1 Answers1

0

After much research on the web and a lot of trial and error, I found the issue: the cache folder I used had permissions 700. After changing them to 777, the issue resolved itself.

Dharman
  • 30,962
  • 25
  • 85
  • 135
AlberichVR
  • 11
  • 1