Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set no cache on only the index.html page in NGINX

Tags:

People also ask

How do I stop index html from caching?

In the root web. config we specify that we don't want to the index. html to cache by setting the cache-control , Pragma and Expires request headers as well as the max-age to 0.

Does Cloudflare cache index html?

Cloudflare doesn't cache html by default.


My current project is almost working with the following configuration:

root %%COMP_WEB_ROOT;

# COMP Static File serving
location /comp {
    alias %%COMP_WEB_ROOT;
    try_files $uri$args $uri$args/ /index.html;
    add_header 'Cache-Control' 'no-cache, no-store, must-revalidate';
}

# Hide the index file, not exposing that path specifically
location = /index.html {
    internal;
}

With this, I am preventing caching for the entire application, which is not desirable, since I only want to prevent the index.html page from storing cache.

So I have tried to put the add_header line inside the second block like this:

root %%COMP_WEB_ROOT;

# COMP Static File serving
location /comp {
    alias %%COMP_WEB_ROOT;
    try_files $uri$args $uri$args/ /index.html;
    error_page 401 = @error401web;
}

# Hide the index file so that we're not exposing that path specifically
location = /index.html {
    internal;
    add_header 'Cache-Control' 'no-cache, no-store, must-revalidate';
}

NGINX is able to run, but index.html seems to still storing the cache as if the add_header isn't there.

Is there some other command I am missing?