Sid
Sid

Reputation: 4997

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

I am looking to deny a particular IP from Nginx for all the locations under a server configuration.

e.g.

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

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

In this approach, I will have to provide deny or allow for each location. Is it possible to do this at server level, which would apply to all locations?

Upvotes: 0

Views: 2626

Answers (1)

samottenhoff
samottenhoff

Reputation: 790

As the Nginx docs point out, the deny rules can be applied to the entire server configuration:

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

Upvotes: 4

Related Questions