Using the Expires Directive in Nginx
📖 Scenario: You are managing a website and want to improve its loading speed by telling browsers to cache static files like images and stylesheets. This helps visitors load your site faster on repeat visits.
🎯 Goal: You will create an Nginx configuration that uses the expires directive to set caching times for different file types.
📋 What You'll Learn
Create a server block listening on port 80
Add a location block for
/images/ to cache images for 30 daysAdd a location block for
/css/ to cache CSS files for 7 daysAdd a location block for
/js/ to cache JavaScript files for 7 daysUse the
expires directive with exact values as specified💡 Why This Matters
🌍 Real World
Web servers use caching headers to reduce load times and bandwidth by telling browsers how long to keep files.
💼 Career
DevOps engineers and system administrators often configure Nginx to optimize website performance and user experience.
Progress0 / 4 steps