Nginx - Restrict/Deny 服务器下所有位置的 IP

Nginx - Restrict/Deny IP for all locations under a server

我希望针对服务器配置下的所有位置拒绝来自 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;
    }
}

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

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

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