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

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

时间: 2024-08-07 05:03:10

[nginx] 对UA为空的请求返回403的相关文章

Spring MVC Post请求返回403错误,Get请求却正常,可能是安全框架引起的前端解决办法

原文地址:http://blog.csdn.net/t894690230/article/details/52404105 困惑:很奇怪,明明在方法上面配置了RequestMethod.POST,POST表单提交却返回403状态码,可是使用GET方式却没问题啊!!! @RequestMapping(value="***", method = { RequestMethod.POST }) public ModelAndView edit() { ModelAndView model =

php请求nginx服务器返回403

在centos的nginx的conf/include里配置了一个虚拟主机,没有配置虚拟域名,默认用了用主机名做域名,将端口换成自定义端口,然而总是返回403. 在网上查说一般有两种原因,一是用户权限问题,我检查了,都是同一个用户组和用户,所以应该不是权限问题: 二是主页问题,发现默认主页index.html是能访问的,应该不是这个问题,当把php页面换成html且把fastcgi_*之类的配置注释掉之后,发现是可以访问的,因此并不是主页设置的问题:但是curl得到的.php页面是源代码,并不是执

ajax请求返回数据,模板中的数据处理

/*ajax请求返回数据,模板中的数据处理*/ function QueryGameAsset(){ var new_start_time=$('#new_start_time').val();//开始时间 var new_end_time=$('#new_end_time').val();//结束时间 if(!new_start_time||!new_end_time){ alert("时间不能为空"); return false; } $.ajax({ url:'/Statisti

nginx静态html页面接收post请求,报405 not allowed错误

nginx静态html页面接收post请求,报405 not allowed错误背景: 对接连连h5快捷支付时,需在连连支付成功页面点击返回商户按钮,跳转到商户的支付成功页面,商户的支付成功页面是html页面不是jsp页面,由于连连返回商户属于form表单提交post请求方式,所以会报405 not allowed 错误.为了让nginx的静态页面能够响应post请求,也在本论坛中找了好多相关的内容.最后用下面这种方式解决了问题. 解决方案:修改nginx.conf配置文件,在server{}中

对GET/POST请求返回cookie中的键值对进行重新组合

get/post请求返回的cookie中并不是所有的键值对我们都需要,我们只需要提取我们需要的进行重新组合就可以了. 如下图是一个GET请求返回的cookie 我需要提取其中的 uin,skey等相关键值对. 以下函数可以完成我们的需要: //using System.Text.RegularExpressions; public string GetCookieByName(List<string> keylist, string cookie) { string str = "&

swift http请求返回json数据并解析

1 AppDelegate.swift // // AppDelegate.swift // QQDemo // // Created by 赵超 on 14-6-21. // Copyright (c) 2014年 赵超. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? fun

根据URL请求 返回XML字符串

public static string GetHttpResponse(string url) { string content = ""; // Create a new HttpWebRequest object.Make sure that // a default proxy is set if you are behind a fure wall. //其中,HttpWebRequest实例不使用HttpWebRequest的构造函数来创建,二是使用WebRequest的C

ionic 发送请求返回一直都是404

在web端调试一直都没有问题,生成app之后发现所有的请求返回的都是404, 断掉wifi和4G之后发送的也是404 原因是未引入插件 解决方法 http://stackoverflow.com/questions/30060534/ajax-requests-fail-after-upgrading-to-cordova-5-0-cordova-android4-0

GET方式的HTTP请求,返回响应体

public static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; /// <summary> /// GET方式的HTTP请求 /// </summary> /// <param name="targetUri">&