Question

Adding an NGINX location block for cache exception, but it's giving me a 404 error.

I have a file called loader.js that I don’t want to cache. So, below is the block of code I have implemented. This is on Django-One-Click app.

# to prevent the caching of loader.js
location ~* loader\.js$ {
    add_header Cache-Control "no-store";
}

I ran sudo nginx -t, it came out successful and restarted nginx. But, once I add the block, loader.js becomes 404. What am I doing wrong?

Thanks.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Location still need to return the file itself.

location ~* loader\.js$ {
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    if_modified_since off;
    expires off;
    root /your/site/folder/with/this/file/;
}

This will serve /loader.js, /whatever/loader.js so be careful. If you call loader always from root, you can use location = /loader.js