首页 > 其他 > 详细

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

时间:2015-04-04 00:00:09      阅读:669      评论:0      收藏:0      [点我收藏+]

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 采用署名-非商业性使用-相同方式共享协议

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

原文:http://blog.csdn.net/orangleliu/article/details/44861585

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!