Score:1

Nginx - Block access to portion of path only, to all but specified IP range

cn flag
Ren

I'm trying block access to a portion of a path via Nginx, unless the source IP is within a specified range.

I think I've got this mostly working through much trial and error, but I seem to run into trouble when the path contains query strings:

Shouldn't work (unless within specified IP range):

/login

/login/

Should work (even publicly):

/login/anything-else

/[email protected]&type=pro

Current location block:

   location ~ ^/(login|login/)$ {
    allow 10.0.102.0/24;
    deny all;
    return 403;
}

Any suggestions would be most welcome, thanks!

Score:0
tr flag

The following configuration only allows incoming requests to the /login URL path to be accessed from the IP address ranges 192.168.1.0/24 and 192.168.2.0/24:

server {
    ...

    location /login {
        if ($remote_addr ~ "^192\.168\.1\.\d{1,3}$") {
            allow all;
        }
        if ($remote_addr ~ "^192\.168\.2\.\d{1,3}$") {
            allow all;
        }
        deny all;
    }

    ...
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.