Skip to content
Foxipa
Code Completion 5 Challenges

Complete the config: Nginx Caching

Fill in cache paths, TTLs by status, stale serving, and request collapsing.

Intermediate ~4 min read

Challenge 1

Declare a 2 GB cache with a shared key zone.

nginx Your answer
proxy_cache_path /var/cache/nginx =api:10m max_size=2g inactive=60m;

Press Ctrl⌘Enter to check your answer

Challenge 2

Keep successful responses fresh for 10 minutes, misses for 1.

nginx Your answer
location / {
     200 301 10m;
    proxy_cache_valid 404 1m;
    proxy_pass http://backend;
}

Press Ctrl⌘Enter to check your answer

Challenge 3

Serve stale content while the cache refreshes and on backend failure.

nginx Your answer
location / {
     error timeout updating;
    proxy_cache api;
    proxy_pass http://backend;
}

Press Ctrl⌘Enter to check your answer

Challenge 4

Collapse a thundering herd of misses into one origin fetch.

nginx Your answer
location / {
     on;
    proxy_cache_lock_timeout 5s;
    proxy_cache api;
}

Press Ctrl⌘Enter to check your answer

Challenge 5

Build the cache key from scheme, host, and URI.

nginx Your answer
location / {
     $scheme$proxy_host$request_uri;
    proxy_cache api;
}

Press Ctrl⌘Enter to check your answer