【发布时间】:2018-01-15 08:16:09
【问题描述】:
我有以下 nginx 配置来阻止某些机器人访问基于用户代理的站点。到目前为止它运行良好,但是我发现被阻止的机器人也无法访问 /robots.txt 文件,因此它们每天继续爬取该站点并出现数百个 403 错误。
map $http_user_agent $block_ua {
default 0;
~*yandexbot 1;
}
server {
# Block bad bots
if ($block_ua) {
return 403;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# other location blocks below...
}
我尝试更改配置允许所有bot访问/robots.txt,如下,但是不行,用curl -I -A "yandexbot" [url]测试仍然返回403 Forbidden。
server {
location = /robots.txt {
try_files $uri $uri/ /index.php?$args;
}
# Block bad bots
if ($block_ua) {
return 403;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# other location blocks below...
}
我应该在配置中添加什么以获得所需的行为?
【问题讨论】:
标签: nginx