Bird
Raised Fist0
Nginxdevops~20 mins

Proxy cache path configuration in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Proxy Cache Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of proxy_cache_path directive with specific keys_zone
What is the effect of the following nginx configuration snippet on the cache zone named 'my_cache'?
Nginx
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off;
ACreates a cache zone 'my_cache' with 1GB shared memory, stores cache files in /data/nginx/cache with 10 level subdirectories, max size 10MB, inactive cache expires after 60 seconds, and enables temp path usage.
BCreates a cache zone 'my_cache' with 10MB shared memory, stores cache files in /data/nginx/cache with 1 and 2 level subdirectories, max size 1GB, inactive cache expires after 60 seconds, and disables temp path usage.
CCreates a cache zone 'my_cache' with 10MB shared memory, stores cache files in /data/nginx/cache with 1 and 2 level subdirectories, max size 1GB, inactive cache expires after 60 minutes, and disables temp path usage.
DCreates a cache zone 'my_cache' with 10MB shared memory, stores cache files in /data/nginx/cache with 2 and 1 level subdirectories, max size 1GB, inactive cache expires after 60 minutes, and enables temp path usage.
Attempts:
2 left
💡 Hint
Focus on the meaning of each parameter: keys_zone size, levels, max_size, inactive, and use_temp_path.
🧠 Conceptual
intermediate
1:30remaining
Understanding cache directory levels in proxy_cache_path
Why does nginx use multiple levels of directories (e.g., levels=1:2) in the proxy_cache_path configuration?
ATo enable nginx to store cache files on multiple disks automatically.
BTo increase cache size by creating nested directories that multiply storage capacity.
CTo encrypt cache files by storing them in multiple directory levels for security.
DTo distribute cache files into subdirectories to avoid too many files in a single directory, improving filesystem performance.
Attempts:
2 left
💡 Hint
Think about how filesystems handle many files in one folder.
❓ Troubleshoot
advanced
2:30remaining
Troubleshooting cache not storing files
Given this proxy_cache_path configuration: proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache_zone:20m max_size=500m inactive=30m; And this proxy_cache usage: proxy_cache cache_zone; Why might nginx not store any cache files in /var/cache/nginx?
AThe directory /var/cache/nginx does not have write permissions for the nginx worker process user.
BThe keys_zone size of 20m is too small to store any cache files.
CThe max_size of 500m is too large and prevents caching.
DThe inactive time of 30m causes immediate cache expiration.
Attempts:
2 left
💡 Hint
Check file system permissions for the cache directory.
✅ Best Practice
advanced
2:00remaining
Best practice for proxy_cache_path keys_zone size
What is the recommended approach when setting the keys_zone size in proxy_cache_path for a high-traffic nginx server?
ASet keys_zone size large enough to hold all active cache keys in shared memory to avoid disk lookups.
BSet keys_zone size as small as possible to save memory, relying on disk for cache keys.
CSet keys_zone size equal to max_size to balance memory and disk usage.
DSet keys_zone size to zero to disable shared memory caching.
Attempts:
2 left
💡 Hint
Think about how nginx uses shared memory for cache keys.
🔀 Workflow
expert
3:00remaining
Correct order to enable proxy caching with custom cache path
Arrange the steps in the correct order to enable proxy caching in nginx with a custom cache directory '/custom/cache' and cache zone 'custom_zone'.
A1,4,2,3
B4,1,2,3
C1,2,4,3
D4,2,1,3
Attempts:
2 left
💡 Hint
Think about preparation before configuration and applying changes last.

Practice

(1/5)
1. What is the main purpose of the proxy_cache_path directive in nginx?
easy
A. To set the maximum number of client connections
B. To specify the backend server IP address
C. To configure SSL certificates for secure connections
D. To define where and how cached files are stored

Solution

  1. Step 1: Understand the role of proxy_cache_path

    The proxy_cache_path directive tells nginx where to save cached files and how to manage them.
  2. Step 2: Compare with other options

    Options A, C, and D relate to connections, SSL, and backend servers, not caching.
  3. Final Answer:

    To define where and how cached files are stored -> Option D
  4. Quick Check:

    proxy_cache_path = cache storage location [OK]
Hint: proxy_cache_path sets cache storage location [OK]
Common Mistakes:
  • Confusing proxy_cache_path with proxy_pass
  • Thinking it sets connection limits
  • Mixing it with SSL configuration
2. Which of the following is the correct syntax to define a proxy cache path in nginx?
easy
A. proxy_cache_path /data/cache keys_zone=mycache:10m max_size=1g inactive=60m;
B. proxy_cache_path /data/cache keys_zone=mycache 10m max_size=1g inactive=60m
C. proxy_cache_path /data/cache keys_zone mycache:10m max_size=1g inactive=60m;
D. proxy_cache_path /data/cache keys_zone=mycache:10m max_size=1g inactive=60m

Solution

  1. Step 1: Check syntax requirements for proxy_cache_path

    The directive requires a semicolon at the end and correct key-value pairs with colons where needed.
  2. Step 2: Identify correct option

    proxy_cache_path /data/cache keys_zone=mycache:10m max_size=1g inactive=60m; has correct syntax with colon in keys_zone, key-value pairs, and ends with a semicolon.
  3. Final Answer:

    proxy_cache_path /data/cache keys_zone=mycache:10m max_size=1g inactive=60m; -> Option A
  4. Quick Check:

    Correct syntax ends with semicolon and uses colons properly [OK]
Hint: Always end proxy_cache_path with semicolon and use colons in keys_zone [OK]
Common Mistakes:
  • Missing semicolon at the end
  • Using space instead of colon in keys_zone
  • Omitting equal signs in parameters
3. Given this nginx configuration snippet:
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mycache:10m max_size=500m inactive=30m;

What happens when a cached file is not accessed for 40 minutes?
medium
A. The cached file is refreshed automatically
B. The cached file remains because max_size is 500m
C. The cached file is removed because it is inactive longer than 30 minutes
D. The cached file is moved to a different cache zone

Solution

  1. Step 1: Understand the inactive parameter

    The inactive=30m means cached files not accessed for 30 minutes are removed.
  2. Step 2: Apply to 40 minutes inactivity

    Since 40 minutes > 30 minutes, the cached file will be removed.
  3. Final Answer:

    The cached file is removed because it is inactive longer than 30 minutes -> Option C
  4. Quick Check:

    inactive=30m means remove after 30 minutes inactivity [OK]
Hint: inactive time removes unused cache files after set duration [OK]
Common Mistakes:
  • Confusing max_size with inactive time
  • Assuming cache refresh happens automatically
  • Thinking cache files move zones
4. You wrote this proxy cache path configuration:
proxy_cache_path /cache keys_zone=mycache 10m max_size=1g inactive=60m;

nginx fails to start. What is the error?
medium
A. Missing colon between keys_zone name and size
B. Invalid max_size value
C. Path /cache does not exist
D. inactive parameter should be in seconds

Solution

  1. Step 1: Check keys_zone syntax

    The keys_zone requires a colon between the zone name and size, e.g., mycache:10m.
  2. Step 2: Identify missing colon

    The config uses keys_zone=mycache 10m missing the colon, causing syntax error.
  3. Final Answer:

    Missing colon between keys_zone name and size -> Option A
  4. Quick Check:

    keys_zone syntax requires colon like mycache:10m [OK]
Hint: keys_zone must have colon between name and size [OK]
Common Mistakes:
  • Forgetting colon in keys_zone
  • Assuming inactive needs seconds
  • Ignoring path existence errors
5. You want to configure nginx to cache responses in /var/cache/nginx with a 20MB keys zone, max cache size 2GB, and remove files inactive for 15 minutes. Which is the correct proxy_cache_path directive?
hard
A. proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2gb inactive=15m;
B. proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2g inactive=15m;
C. proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=1024m inactive=15m;
D. proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2g inactive=900;

Solution

  1. Step 1: Verify keys_zone size and path

    Keys zone size is 20m and path is /var/cache/nginx, both correct in all options.
  2. Step 2: Check max_size and inactive syntax

    Max size should be 2g (gigabytes), inactive time 15m (minutes). proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2g inactive=15m; uses correct units and syntax.
  3. Step 3: Identify errors in other options

    proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2gb inactive=15m; uses '2gb' (invalid unit), C uses 1024m (1GB not 2GB), D uses inactive=900 (seconds, but default is minutes and needs 's').
  4. Final Answer:

    proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2g inactive=15m; -> Option B
  5. Quick Check:

    Use correct units: m for MB, g for GB, and time units with m for minutes [OK]
Hint: Use correct units: m for MB, g for GB, and m for minutes [OK]
Common Mistakes:
  • Using invalid units like 'gb' instead of 'g'
  • Confusing inactive time units
  • Using seconds without 's' suffix
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard