0
0
Nginxdevops~10 mins

Proxy cache basics in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable proxy caching in nginx.

Nginx
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m [1] inactive=60m;
Drag options to blanks, or click blank then click option'
Amax_cache_size=1g
Bmax_size=1g
Cmax_cache=500m
Dmax_size=100m
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'max_cache' instead of 'max_size' causes nginx to ignore the limit.
Setting size without units (like '100') causes errors.
2fill in blank
medium

Complete the code to set the proxy cache key to the request URI.

Nginx
proxy_cache_key [1];
Drag options to blanks, or click blank then click option'
A$request_method
B$host
C$request_uri
D$remote_addr
Attempts:
3 left
💡 Hint
Common Mistakes
Using $request_method caches by HTTP method, which is not unique enough.
Using $remote_addr caches by client IP, which is unrelated to the resource.
3fill in blank
hard

Fix the error in the proxy cache configuration to enable caching for 10 minutes.

Nginx
proxy_cache_valid 200 302 [1];
Drag options to blanks, or click blank then click option'
A10min
B10m
C600s
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using '10' without units causes nginx to ignore the setting.
Using '10min' is not recognized by nginx.
4fill in blank
hard

Fill both blanks to set cache control headers and enable proxy caching in the location block.

Nginx
location / {
    proxy_cache [1];
    add_header [2] 'HIT from cache';
}
Drag options to blanks, or click blank then click option'
Amy_cache
BX-Cache-Status
CCache-Control
Dcache_zone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Cache-Control' as header name here is incorrect for cache hit indication.
Using 'cache_zone' instead of the actual cache zone name causes errors.
5fill in blank
hard

Fill all three blanks to create a dictionary of cached responses with keys as request URIs and values as status codes greater than 200.

Nginx
cached_responses = { [1]: [2] for [3] in responses if responses[[1]] > 200 }
Drag options to blanks, or click blank then click option'
Auri
Bresponses[uri]
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for key and loop variable causes errors.
Using 'status' as loop variable without defining it causes NameError.