代码之家  ›  专栏  ›  技术社区  ›  Thomas Jensen

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

  •  3
  • Thomas Jensen  · 技术社区  · 14 年前

    如果没有相对路径,我希望有一个默认的robots.txt文件从共享位置(绝对路径)提供。

    我尝试了这个,但运气不好:

    location = /robots.txt {
        expires 30d;
        add_header Cache-Control public;
        try_files /robots.txt /var/www/shared/robots.txt =404;
    }
    

    但它只返回404。

    1 回复  |  直到 14 年前
        1
  •  4
  •   Thomas Jensen    14 年前

    我最终得到了一个似乎有效的结果:

    location = /robots.txt {
        expires 30d;
        add_header Cache-Control public;
        try_files /robots.txt @shared;
    }
    
    location @shared {
        root /var/www/shared;
    }
    

    不过,我必须承认,我更喜欢“try_files”,但它似乎不适用于绝对路径。

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