有些时候,需要阻止某些用户代理访问网站,比如ab,wget,curl等等,这就需要使用到$http_user_agent变量。
修改nginx.conf
1
2
3
4
5
6
7
|
if
(
$
http_user_agent
~
*
(
Wget
|
ab
)
)
{
return
403
;
}
if
(
$
http_user_agent
~
*
LWP
::
Simple
|
BBBike
|
wget
)
{
return
403
;
}
|
重启nginx
1
|
# /usr/local/nginx-1.7.0/sbin/nginx -s reload
|
收 藏
转载请注明:成长的对话 » Nginx阻止用户代理