欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-27 12:54:00
...

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>