通过 Nginx 将爬虫和正常用户访问分开到不同的后端运行
1. [代码]定义 Map 跳至 [全屏预览]view source
print?
1map $http_user_agent $is_bot {
2 default 0;
3 ~bot[^a-z] 1;
4 ~pider[^a-z] 1;
5 'Yahoo! Slurp China' 1;
6 'Mediapartners-Google' 1;
7}
2. [代码]定义 Location
1location @bots {
2 proxy_pass http://osc_bot;
3}
3. [代码]处理爬虫请求
1location / {
2 error_page 418 =200 @bots;
3 if ($is_bot) {
4 return 418;
5 }
6 proxy_pass http://osc_tomcats;
7}
页:
[1]