0
0
Nginxdevops~15 mins

Cache validity rules in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Cache Validity Rules in Nginx
📖 Scenario: You are managing a web server using Nginx. To improve performance, you want to cache responses from your backend server. However, you need to control when the cached content is considered valid or stale.This project will guide you through setting up cache validity rules in Nginx configuration.
🎯 Goal: Build an Nginx configuration that sets up a cache zone and defines cache validity rules to control how long responses are cached based on HTTP status codes.
📋 What You'll Learn
Create a cache zone named my_cache with 10MB of storage
Set cache validity for HTTP status 200 to 5 minutes
Set cache validity for HTTP status 404 to 1 minute
Set cache validity for HTTP status 500 to 30 seconds
Print the final Nginx configuration snippet
💡 Why This Matters
🌍 Real World
Web servers often cache responses to speed up delivery and reduce load. Cache validity rules ensure users get fresh content when needed.
💼 Career
DevOps engineers and system administrators configure Nginx caching to optimize web performance and reliability.
Progress0 / 4 steps
1
Create a cache zone
Create a cache zone named my_cache with 10m of storage in the http block.
Nginx
Need a hint?

Use proxy_cache_path directive with keys_zone=my_cache:10m inside the http block.

2
Add cache validity rules
Inside the http block, add a proxy_cache_valid directive to set cache validity for HTTP status 200 to 5m.
Nginx
Need a hint?

Use proxy_cache_valid 200 5m; to set cache validity for status 200.

3
Add more cache validity rules
Add proxy_cache_valid directives inside the http block to set cache validity for HTTP status 404 to 1m and for HTTP status 500 to 30s.
Nginx
Need a hint?

Add proxy_cache_valid 404 1m; and proxy_cache_valid 500 30s; inside the http block.

4
Print the final Nginx cache configuration
Print the complete http block configuration with the cache zone and all cache validity rules.
Nginx
Need a hint?

Use print statements to output each line of the configuration exactly as shown.