nginx 设置禁止搜索引擎蜘蛛爬取内容
Linux 2023/3/28 21:01:15 点击:不统计
在做web服务或者接口过程中,有使用默认80端口服务的,某些情况下,会对外提供服务,那么在这种情况下,百度、搜索引擎就会访问到,那怎么在nginx配置呢
很简单,在nginx server 配置如下
locaiton / {
if ($http_user_agent ~* "Baiduspider|360Spider|bingbot|Googlebot|Sogou|semrush|petalsearch") {
access_log off;
return 404;
}
}
这里是写了常见的搜索引擎蜘蛛。 通过 useragent 进行判断。
我上面的配置
access_log off; #不记录日志
return 404; # 返回网络状态码404 当然也可以更改为503