A proxy cache in Nginx stores copies of responses from upstream servers. It helps serve repeated requests faster by delivering cached content instead of fetching it again.
Click to reveal answer
beginner
Which directive in Nginx enables proxy caching?
The proxy_cache directive enables proxy caching by specifying the cache zone to use for storing cached responses.
Click to reveal answer
intermediate
What does the proxy_cache_path directive do?
It defines the location on disk where cached files are stored, the cache size, and other cache parameters like inactive time and keys zone name.
Click to reveal answer
intermediate
How does Nginx decide when to serve cached content?
Nginx serves cached content if it exists and is valid (not expired). It uses cache keys to match requests and respects cache control headers and expiration settings.
Click to reveal answer
intermediate
What is the role of proxy_cache_valid directive?
It sets how long responses with specific HTTP status codes are considered valid in the cache before being refreshed from the upstream server.
Click to reveal answer
Which directive sets the disk location for Nginx proxy cache?
Aproxy_cache_valid
Bproxy_cache_key
Cproxy_cache_path
Dproxy_cache_use_stale
✗ Incorrect
The proxy_cache_path directive defines the directory on disk where cached files are stored.
What happens if Nginx does not find a cached response for a request?
AIt returns an error
BIt fetches the response from the upstream server
CIt serves a stale cached response
DIt redirects the request
✗ Incorrect
If no cached response exists, Nginx fetches the content from the upstream server.
Which directive controls how long cached responses stay valid?
Aproxy_cache_key
Bproxy_cache_use_stale
Cproxy_cache_methods
Dproxy_cache_valid
✗ Incorrect
The proxy_cache_valid directive sets the time cached responses remain valid.
What is the purpose of the proxy_cache_key directive?
ASpecifies the key used to store and retrieve cached responses
BDefines the cache zone name
CSets cache expiration time
DEnables proxy caching
✗ Incorrect
The proxy_cache_key directive defines how requests are identified in the cache.
Which directive enables proxy caching in an Nginx location block?
Aproxy_cache
Bproxy_pass
Cproxy_set_header
Dproxy_cache_path
✗ Incorrect
The proxy_cache directive activates caching using a defined cache zone.
Explain how Nginx proxy cache improves website performance.
Think about how saving copies helps avoid repeated work.
You got /4 concepts.
Describe the key Nginx directives needed to set up proxy caching.
Focus on directives that define storage, enable cache, and control cache behavior.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of proxy_cache in nginx?
easy
A. To store copies of web responses for faster delivery
B. To block unwanted web requests
C. To encrypt web traffic
D. To balance load between servers
Solution
Step 1: Understand proxy_cache role
The proxy_cache directive tells nginx to save copies of responses from the backend server.
Step 2: Identify purpose of caching
Storing these copies helps nginx deliver content faster to users without asking the backend every time.
Final Answer:
To store copies of web responses for faster delivery -> Option A
Quick Check:
proxy_cache = store copies for speed [OK]
Hint: proxy_cache saves responses to speed up delivery [OK]
Common Mistakes:
Confusing proxy_cache with load balancing
Thinking proxy_cache encrypts traffic
Assuming proxy_cache blocks requests
2. Which of the following is the correct syntax to define a cache path in nginx?
easy
A. proxy_cache_path /data/nginx/cache keys_zone=mycache:10m levels=1:2
B. proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=mycache:10m;
C. proxy_cache_path keys_zone=mycache:10m /data/nginx/cache levels=1:2;
D. proxy_cache_path levels=1:2 keys_zone=mycache:10m /data/nginx/cache;
Solution
Step 1: Recall correct order of proxy_cache_path
The correct syntax starts with the cache directory path, then options like levels and keys_zone.
Step 2: Match syntax with options order
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=mycache:10m; correctly places the path first, followed by levels and keys_zone with proper separators and semicolon.
Final Answer:
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=mycache:10m; -> Option B
Quick Check:
Path first, then options = proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=mycache:10m; [OK]
Hint: Cache path starts with directory, then options [OK]