对UA为空的请求返回403,nginx,uanginx


[nginx] 对UA为空的请求返回403,nginxua


热度1 评论 243 www.BkJia.Com  网友分享于:  2015-04-06 08:04:51     浏览数35866次

[nginx] 对UA为空的请求返回403,nginxua

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;
                return 403;
            }

            default_type   text/html;
            content_by_lua '
                ngx.say("<h1>你好 baby </h1>")
            ';
        }

模拟请求

lzz@ubuntu:conf$ curl 'http://localhost'
<h1>你好 baby </h1>
lzz@ubuntu:conf$ curl -H "User-Agent:" 'http://localhost'
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>ngx_openresty/1.2.6.1</center>
</body>
</html>

声明: 
本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处http://blog.csdn.net/orangleliu/article/details/44861585 
作者orangleliu 采用署名-非商业性使用-相同方式共享协议

相关内容

    暂无相关文章