Nginx - 如何在使用try_files时为index.html添加头信息

7
我有以下配置(用于Angular应用程序):

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

现在我想只为index.html添加标题,而不是其他任何文件。如何做到这一点?

尝试添加 location= /index.html { //在这里添加指令 } - Mattia Dinosaur
http://nginx.org/en/docs/http/ngx_http_core_module.html#location - Mattia Dinosaur
1
具有“=”前缀的指令完全匹配查询。如果找到,则停止搜索。 - Mattia Dinosaur
1
https://dev59.com/JW435IYBdhLWcg3wvy05#5238430 - Mattia Dinosaur
1个回答

5
使用“=”修饰符可以定义URI和位置的精确匹配。如果找到了精确匹配,搜索将终止。
因此,您可以使用以下配置:
location =/index.html {
      add_header "Cache-Control" "no-cache" ;
}
location / {
    rewrite ^(.*)  /index.html  break;

}

您可以在以下链接中获取更多信息:

break和last的区别

以“=”前缀开头的指令


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接