更正nginx配置以防止某些文件夹的索引

时间:2017-03-29 13:25:15

标签: nginx googlebot

我正在尝试阻止使用x-robots tag对某些文件夹中的内容编制索引,并在Nginx配置后使用

location ~ .*/(?:archive|filter|topic)/.* {
add_header X-Robots-Tag "noindex, follow";      
}

内容仍然编入索引,我无法调试Nginx配置。

我的问题:我使用的配置是否正确,我应该等到googlebot重新抓取内容并取消内容索引?或者我的配置错了?

1 个答案:

答案 0 :(得分:3)

您撰写的配置是正确的。我给出了一个警告(假设您的配置是标准的):

当结果代码为200,201,204,206,301,302,303,304或307时(例如,内容与磁盘文件匹配,发布重定向等),它将仅输出X-Robots-Tag )。因此,如果您有/archive/index.html,则http://yoursite.com/archive/的匹配将显示标题。如果index.html不存在(404),则您无法看到该标记。

always参数将输出所有响应代码的标头,假设处理了位置块:

location ~ .*/(?:archive|filter|topic)/.* {
    add_header X-Robots-Tag "noindex, follow" always;      
}

另一个选项将保证在URI匹配时输出标头。这对于可能无法处理位置块的可能性很有用(由于短路,例如重写等returnlast):

http {
    ...
    map $request_uri $robot_header {
        default "";
        ~.*/(?:archive|filter|topic)/.* "noindex, follow";
    }

    server {
        ...
        add_header X-Robots-Tag $robot_header;
        ...
    }
相关问题