更新时间:2022-05-31 15:59:36
在为客户端请求交付内容之前,您通常希望确保发起请求的客户端是人,而不是机器人或者爬虫程序。通常,爬虫程序或者机器人发出的请求都会带有一些请求特征。您可以在CDN Pro上针对这些特征定义一些用户交互策略,以识别请求是否由机器人发出。以下边缘逻辑代码演示了如何提示用户通过单击按钮来接收请求:
location /protected/ {
if ($cookie_validated = '') { #check the existence of the cookie 'validated'
add_header Set-Cookie 'validated=1; Max-Age=60';
add_header Content-Type 'text/html' policy=overwrite;
return 200 '<!DOCTYPE html>
<html>
<script>
alert("Human, click OK to proceed.");
location.href="$request_uri";
</script>
</html>';
}
# continue loading the page from origin or cache
origin_pass my_origin;
}
您可以通过此方式,设置更多复杂的防爬策略。