[Nginx] returns 403 for a UA-empty request

Source: Internet
Author: User
Tags php tutorial

Nginx blocking blank user agent.
Sometime apps ' Backgroud request always visit a URL, and these requests ' user agent was black, so I want block them.

Nginx Configuration for a location

       location / {            if ($http_user_agent""){                access_log off;                return403;            }            default_type   text/html;            '                ngx.say("

你好 baby

") '; }

Impersonation Request

lzz@ubuntu:conf$ 'http://localhost'

你好 baby </h1>

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

Statement:
This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/44861585
Author Orangleliu using Attribution-NonCommercial-sharing protocol in the same way

The above describes the [nginx] on the UA is empty request returned 403, including the content, I hope to be interested in the PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.