时间:2021-07-01 10:21:17 帮助过:11人阅读
nginx blocking blank user agent .
sometime apps’ backgroud request always visit a url, and these requests’ user agent is black, so I want block them.
针对一个location的nginx配置
location / {
if ($http_user_agent = ""){
access_log off;
return403;
}
default_type text/html;
content_by_lua '
ngx.say("你好 baby
")
';
}
模拟请求
lzz@ubuntu:conf$ curl 'http://localhost'
你好 baby </h1>
lzz@ubuntu:conf$ curl -H "User-Agent:" 'http://localhost'
<html><head><title>403 Forbiddentitle>head><bodybgcolor="white"><center><h1>403 Forbiddenh1>center><hr><center>ngx_openresty/1.2.6.1center>body>html>
声明:
本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处http://blog.csdn.net/orangleliu/article/details/44861585
作者orangleliu 采用署名-非商业性使用-相同方式共享协议
以上就介绍了[nginx] 对UA为空的请求返回403,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。