Nginx 阻止用户代理 "-"

标签 nginx http-headers user-agent access-control ngx-http-rewrite-module

我获得的某种访问权限导致我的服务器出现问题:

172.68.28.210 - - [03/Jul/2016:13:41:06 -0300] " "GET / HTTP/1.1" 502 166 "-" "-"

我什至想阻止 $HTTP_USER_AGENT,但这次尝试没有成功。

if ($http_user_agent = "-") {
        return 403;
    }

有人会知道出了什么问题吗?

最佳答案

这是因为 $http_user_agent 变量可能根据上下文具有不同的值。

如果请求中不存在 header ,则 it'll present itself as - in your access_log ,同时 if 语句中仍然是空的。

因此,也许以下才是您想要的:

if ($http_user_agent = "") {
    return 403;
}

关于Nginx 阻止用户代理 "-",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38172128/

相关文章:

ssl - 引用网站在 Ubuntu 上正确使用端口 8080,使用带 SSL 的 Nginx

node.js - 在服务器中部署时将 API 请求路由到 MEAN 应用程序中的 Node 服务器

cookies - 在 cloudflare worker header.set 'Set-Cookie' 函数的 ('Set-Cookie' header 中设置多个 cookie

JavaScript 条件中的 PHP header ?

iphone - 如果用户在 iPhone 和 window.navigator.standalone == true 上,则在 userAgent 时更改 css 显示

php - 为什么 IE 用户代理字符串在 POST 表单上变化如此之大?

Android 流到 rstp 服务器并使用 nginx 转换为 rtmp

amazon-web-services - Amazon EKS上带有NGINX Ingress Controller 的网络负载均衡器始终返回503错误

api - PHPUnit - getallheaders 不起作用

javascript - URL 中的 HTML 和 CSS 导致 404 错误(用户代理 = Trident/4.0)