What is the purpose of the proxy_cache_path directive in nginx?
It defines the location on disk where nginx stores cached responses from proxied servers. This helps speed up repeated requests by serving cached content.
Click to reveal answer
intermediate
Which parameters can you set in proxy_cache_path to control cache size and behavior?
You can set parameters like levels (directory structure), keys_zone (shared memory zone name and size), max_size (maximum cache size), inactive (time before cached items expire), and use_temp_path.
Click to reveal answer
intermediate
Explain the role of the keys_zone parameter in proxy_cache_path.
It defines a shared memory zone that stores cache keys and metadata. This zone allows nginx worker processes to share cache information efficiently.
Click to reveal answer
beginner
What does the levels parameter do in proxy_cache_path?
It sets the directory structure depth for storing cached files. For example, levels=1:2 creates a two-level folder hierarchy to avoid too many files in one directory.
Click to reveal answer
beginner
How do you enable proxy caching for a location block after configuring proxy_cache_path?
Use the proxy_cache directive inside the location block with the name of the cache zone defined in keys_zone. For example, proxy_cache my_cache_zone;.
Click to reveal answer
What does the max_size parameter in proxy_cache_path control?
AMaximum number of worker processes
BMaximum size of HTTP request body
CMaximum number of cached keys in memory
DMaximum size of the cache on disk
✗ Incorrect
max_size limits how much disk space the cache can use.
Which parameter defines the shared memory zone for caching in nginx?
Aproxy_cache_key
Bkeys_zone
Cproxy_cache_path
Dproxy_cache_valid
✗ Incorrect
keys_zone is a parameter inside proxy_cache_path that defines the shared memory zone.
What is the effect of setting levels=1:2 in proxy_cache_path?
ACache files are stored in a two-level directory structure
BCache files are stored in a single directory
CCache files are stored in three nested directories
DCache files are stored in memory only
✗ Incorrect
This creates a two-level folder hierarchy with 1-character named directories at the first level and 2-character named directories at the second level.
How do you activate caching for a specific location in nginx?
AUse <code>cache_enable</code> directive
BUse <code>proxy_cache_path</code> inside the location block
CUse <code>proxy_cache</code> directive with the cache zone name
DUse <code>cache_zone</code> directive
✗ Incorrect
proxy_cache enables caching using the named cache zone.
What happens if the cache size exceeds the max_size limit?
AOld cached files are deleted to free space
BNew cache files are rejected
CNginx stops serving cached content
DCache size automatically increases
✗ Incorrect
Nginx removes old cache files to keep the cache size within the limit.
Describe how to configure proxy cache storage in nginx using proxy_cache_path. Include key parameters and their roles.
Think about where cache files go, how nginx organizes them, and how it limits cache size.
You got /5 concepts.
Explain the steps to enable proxy caching for a website location after setting up the cache path.
Focus on linking the cache storage setup with the location block configuration.
You got /4 concepts.
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
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.
Step 2: Compare with other options
Options A, C, and D relate to connections, SSL, and backend servers, not caching.
Final Answer:
To define where and how cached files are stored -> Option D
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
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.
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.
Final Answer:
proxy_cache_path /data/cache keys_zone=mycache:10m max_size=1g inactive=60m; -> Option A
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]
The keys_zone requires a colon between the zone name and size, e.g., mycache:10m.
Step 2: Identify missing colon
The config uses keys_zone=mycache 10m missing the colon, causing syntax error.
Final Answer:
Missing colon between keys_zone name and size -> Option A
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
Step 1: Verify keys_zone size and path
Keys zone size is 20m and path is /var/cache/nginx, both correct in all options.
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.
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').
Final Answer:
proxy_cache_path /var/cache/nginx keys_zone=mycache:20m max_size=2g inactive=15m; -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.