加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

退回到Nginx中的默认/共享文件

发布时间:2020-12-13 20:57:39 所属栏目:Nginx 来源:网络整理
导读:如果没有相对的位置,我希望从共享的位置(绝对路径)提供默认的robots.txt文件. 我没有运气尝试过这个: location = /robots.txt { expires 30d; add_header Cache-Control public; try_files /robots.txt /var/www/shared/robots.txt =404;} 但是它只返回404.

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

我没有运气尝试过这个:

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

但是它只返回404.

最佳答案
我最终得到了似乎可行的方法:

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读