在nginx中回退到默认/共享文件

3
我希望能够从共享位置(绝对路径)提供默认的robots.txt文件,如果没有相对路径的话。
我尝试了这个方法,但没有成功:
location = /robots.txt {
    expires 30d;
    add_header Cache-Control public;
    try_files /robots.txt /var/www/shared/robots.txt =404;
}

但它只返回404错误。
1个回答

4
我最终得到了以下代码,看起来是可行的:
location = /robots.txt {
    expires 30d;
    add_header Cache-Control public;
    try_files /robots.txt @shared;
}

location @shared {
    root /var/www/shared;
}

不过我必须承认,我更喜欢“try_files”,但是它似乎无法处理绝对路径。

如果有更好/其他的解决方案,我会非常乐意看到!


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