8

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?

4

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.