我有一个具有这种结构的static
文件夹,
└── static
├── images
├── locales
└── robots.txt
我为此文件夹设置了location
指令,以公开地缓存文件。
location /static {
access_log off;
log_not_found off;
expires 1y;
autoindex off;
add_header Cache-Control "public";
}
我想将 locales 文件夹内的所有Cache-Control
文件的public, stale-while-revalidate=60, stale-if-error=60
标头更改为json
。
我尝试过嵌套位置,但是没有成功,
location /static {
access_log off;
log_not_found off;
expires 1y;
autoindex off;
add_header Cache-Control "public";
location /static/locales/.*/.*\.json$ {
expires 1w;
add_header Cache-Control "public,stale-while-revalidate=60, stale-if-error=60";
}
}
答案 0 :(得分:0)
显然,我真的很接近解决方案,我所需要的只是在嵌套位置的正则表达式前面添加~
,
这行得通!
location /static {
access_log off;
log_not_found off;
expires 1y;
autoindex off;
add_header Cache-Control "public";
location ~ /static/locales/.*/.*\.json$ {
expires 1w;
add_header Cache-Control "public,stale-while-revalidate=60, stale-if-error=60";
}
}