Heim  >  Artikel  >  Backend-Entwicklung  >  [nginx] 对UA为空的请求返回403

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

WBOY
WBOYOriginal
2016-08-08 09:26:451440Durchsuche

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配置

<code>       location / {
            <span>if</span> (<span>$http_user_agent</span> = <span>""</span>){
                access_log off;
                <span>return</span><span>403</span>;
            }

            default_<span>type</span>   text/html;
            content_by_lua <span>'
                ngx.say("<h1>你好 baby </h1>")
            '</span>;
        }</code>

模拟请求

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

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

以上就介绍了[nginx] 对UA为空的请求返回403,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn