【问题标题】:Nginx - Restrict/Deny IP for all locations under a serverNginx - 限制/拒绝服务器下所有位置的 IP
【发布时间】:2015-07-06 12:59:22
【问题描述】:

我希望拒绝来自 Nginx 的特定 IP 用于服务器配置下的所有位置。

例如

server {
    listen       443;
    server_name  localhost;  
    location / {
        root /data/www;
        deny 127.0.0.1;
    }

    location /images/ {
        root /data;
        deny 127.0.0.1;
    }
}

在这种方法中,我必须为每个位置提供拒绝或允许。是否可以在服务器级别执行此操作,这将适用于所有位置?

【问题讨论】:

  • 你读过文档吗?您可以轻松地在服务器级别使用deny
  • 我做了一些谷歌搜索,但没有找到明确的答案。我的错。谢谢。

标签: nginx configuration ip


【解决方案1】:

作为Nginx docs point out,拒绝规则可以应用于整个服务器配置:

Syntax: allow address | CIDR | unix: | all;
Default:    —
Context:    http, server, location, limit_except

【讨论】:

    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 2013-02-17
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    相关资源
    最近更新 更多