caching控制no-cache,但不在Nginx的子文件夹中

我在Nginx中使用这个规则

location ~ /app/(?<code>...)/acme/?(?<uri>.*) { add_header Cache-Control "max-age=0, no-cache, no-store, must-revalidate"; proxy_pass http://int-srv/$code/acme/dev/$uri; } 

这增加了我上面在调用中写的Cache-control头

 /app/abc/acme /app/abc/acme/assets /app/abc/acme/assets/js /app/abc/acme/assets/css /app/abc/acme/anything 

我只希望caching控制头被应用到/ app / abc / acme,因为当调用这个端点时,响应是我们的index.html的内容。 我不想caching它,它目前的工作很好。

如果你正在考虑使用index.html制定规则,不幸的是,它不会工作,因为我没有看到我们直接打电话给文件(/app/abc/acme/index.html) Chromedebugging器工具

所以基本上这是我想要的

 /app/abc/acme - apply cache-control no-cache,etc header to this location only /app/abc/acme/assets - don't want cache-control header /app/abc/acme/assets/js - don't want cache-control header /app/abc/acme/assets/css - don't want cache-control header /app/abc/acme/anything - - don't want cache-control header 

如果你认为我做的不好,请告诉我。

您可以使用两个位置,一个与较短的URL匹配。 例如:

 location ~ ^/app(?<code>/...)/acme/(?<stuff>.*)$ { add_header Cache-Control "max-age=0, no-cache, no-store, must-revalidate"; rewrite ^ $code/acme/dev/$stuff break; proxy_pass http://int-srv; } location ~ ^/app(?<code>/...)/acme$ { rewrite ^ $code/acme/dev break; proxy_pass http://int-srv; } 

variables名称$uri已经被系统定义,所以你应该使用不同的名称。

在正则expression式位置内部使用带有proxy_pass指令的URI组件显然起作用,但是没有logging。 事实上, 这个文件指出:

当使用正则expression式指定位置时。 在这种情况下,应该指定指令而不使用URI

所以我的例子使用rewrite ... break