Operations 2 min read
How to Disable Browser Caching in Nginx: Two Effective Methods
Learn two practical Nginx configurations to prevent browsers from caching HTML files by setting appropriate Cache-Control, Pragma, and Expires headers, with examples for both standard location blocks and conditional directives, ensuring fresh content delivery for your web applications.
Practical DevOps Architecture
Practical DevOps Architecture
Method 1:
location / {
index index.html index.htm;
add_header Cache-Control no-cache,no-store;
try_files $uri $uri/ /index.html;
include mime.types;
if ($request_filename ~* .*\.(htm|html)$) {
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
}Method 2:
location / {
index index.html index.htm;
add_header Cache-Control no-cache,no-store;
try_files $uri $uri/ /index.html;
include mime.types;
#if ($request_filename ~* .*\.(htm|html)$) {
# add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
#}
}Additional specific block to handle the index file directly:
location = /index.html {
#add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}Original Source
Signed-in readers can open the original source through BestHub's protected redirect.
Republication Notice
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Reader feedback
How this landed with the community
Rate this article
Was this worth your time?
Discussion
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
