我试图拒绝 bingbot 访问 /wp-admin 和 /wp-login.php,但我的 nginx 配置有问题。我从以下内容开始:
location ~ /(wp-admin|wp-login\.php) {
if ($http_user_agent ~* "(alltheweb|baidu|bingbot|googlebot|msnbot|slurp)") {
return 403;
break;
}
}
# Allow any php files to run
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/lib/php/php.socket;
}
这对于阻止 bingbot 非常有效,但它也不会执行wp-login.php
;它把它当作一个静态文件。我想“好吧,你不会陷入更多的位置块”,所以我将 php 代码复制到更高的代码中:
location ~ /(wp-admin|wp-login\.php) {
if ($http_user_agent ~* "(alltheweb|baidu|bingbot|googlebot|msnbot|slurp)") {
return 403;
break;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/lib/php/php.socket;
}
}
# Allow any php files to run
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:/var/lib/php/php.socket;
}
这使我能够再次登录而不是下载wp-login.php
,但现在 bingbot 再次获得 HTTP 200 OK!如何有选择地正确返回 403 或 php 处理程序?