Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable caching of a single file with try_files directive

Tags:

nginx

angular

I'm serving Angular 2 application with nginx using location section this way:

location / {   try_files $uri $uri/ /index.html =404; } 

try_files directive tries to find the requested uri in root directory and if it fails to find one it simply returns index.html

How to disable caching of index.html file?

like image 298
Roman Kolesnikov Avatar asked Jan 13 '17 09:01

Roman Kolesnikov


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.

What is index in nginx?

The index directive defines the index file's name (the default value is index.html ). To continue with the example, if the request URI is /images/some/path/ , NGINX delivers the file /www/data/images/some/path/index.html if it exists. If it does not, NGINX returns HTTP code 404 (Not Found) by default.


1 Answers

Found a solution using nginx named locations:

location / {     gzip_static on;     try_files $uri @index; }  location @index {     add_header Cache-Control no-cache;     expires 0;     try_files /index.html =404; } 
like image 146
Roman Kolesnikov Avatar answered Sep 29 '22 17:09

Roman Kolesnikov