0
0
Nginxdevops~20 mins

Expires directive in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Expires Directive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the effect of this Expires directive in nginx?
Given the nginx configuration snippet:
location /images/ {
  expires 30d;
}

What will be the Cache-Control header value sent to clients for files under /images/?
Nginx
location /images/ {
  expires 30d;
}
ACache-Control: max-age=3600
BCache-Control: max-age=2592000
CCache-Control: no-cache
DCache-Control: no-store
Attempts:
2 left
💡 Hint
30d means 30 days in seconds for max-age.
🧠 Conceptual
intermediate
1:30remaining
How does the 'expires' directive affect browser caching?
Which statement best describes the role of the 'expires' directive in nginx?
AIt sets how long browsers should cache the resource before requesting it again.
BIt disables caching completely for the resource.
CIt forces the browser to always revalidate the resource with the server.
DIt compresses the resource before sending it to the client.
Attempts:
2 left
💡 Hint
Think about cache duration.
Configuration
advanced
2:00remaining
Which nginx configuration sets no caching for CSS files?
You want to configure nginx to prevent caching of CSS files. Which configuration snippet achieves this?
A
location ~* \.css$ {
  expires 1h;
}
B
location ~* \.css$ {
  expires max;
}
C
location ~* \.css$ {
  expires off;
}
D
location ~* \.css$ {
  expires 30d;
}
Attempts:
2 left
💡 Hint
'expires off;' disables caching.
Troubleshoot
advanced
2:00remaining
Why is the Expires header not set as expected?
You configured nginx with:
location /static/ {
  expires 7d;
}

But clients do not receive the Expires header. What is a likely cause?
AThe 'expires' directive is inside a location block that is never matched.
BThe 'expires' directive requires a reload of the server to take effect.
CThe 'expires' directive only works for dynamic content, not static files.
DThe 'expires' directive conflicts with gzip compression.
Attempts:
2 left
💡 Hint
Check if the location block matches the request path.
Best Practice
expert
2:30remaining
What is the recommended way to set long cache expiration for versioned static assets?
You have static assets with filenames including version hashes (e.g., app.abc123.js). What is the best practice for setting the 'expires' directive in nginx?
ADo not set 'expires' and rely on browser defaults.
BSet 'expires off;' to disable caching to avoid stale files.
CSet 'expires 1h;' to cache for a short time and reduce stale content risk.
DSet 'expires max;' to cache assets indefinitely since filenames change on updates.
Attempts:
2 left
💡 Hint
Versioned filenames allow safe long caching.