以下代碼是禁止直接訪問,但匹配并排除搜索引擎蜘蛛
nginx站點配置文件中加入以下節(jié)點:
location = /robots.txt {
if ($http_user_agent !~* "spider|bot|yahoo|sogou") {
return 404;
}
}
1
2
3
4
5
location = /robots.txt {
if ($http_user_agent !~* "spider|bot|yahoo|sogou") {
return 404;
}
}
然后重載nginx配置
/usr/local/shuyangwang/nginx/sbin/nginx -s reload (此配置文件路徑以你安裝為準)