4

I have the following config (for an Angular app):

location / {
    try_files $uri /index.html;
    add_header "Cache-Control" "no-cache" ;
}

Now I would like to add that header only for index.html, but not for any other files. How to do that?

user140547
  • 7,250
  • 2
  • 23
  • 73

1 Answers1

3

using the “=” modifier it is possible to define an exact match of URI and location. If an exact match is found, the search terminates.

so you can use this configure :

location =/index.html {
      add_header "Cache-Control" "no-cache" ;
}
location / {
    rewrite ^(.*)  /index.html  break;

}

you can find more information in

different in break and last

Directives with the "=" prefix

Community
  • 1
  • 1
Mattia Dinosaur
  • 830
  • 9
  • 23