I have Nginx with many defined "services" (websites). I would like to deny access to all of them for lots of IP addresses (mostly international), but at the same time I want to "allow" unrestricted access to some publicly accessible websites. Is it possible to do that with the free Nginx for Windows?
Here's the structure of my config file:
http {
# common statements here;
server {
server_name publicsite.web;
# some settings;
allow all;
}
deny 1.0.0.0/8;
deny 2.0.0.0/8;
# everything below should be denied to the listed IP's
server {
server_name privatesite1.domain.web;
# some settings;
}
server {
server_name privatesite99.web;
# some settings;
}
}
I tried configuration like that, but the "publicsite.web" gets denied for IP's listed below its server{} block, I guess because they are on http level, even though they're listed below.
I understand that the easiest option would be to list all "deny" IP's in a separate file (which by the way already is) and include them inside of every server{} block which should honor the denying. Giving that there might be up to a hundred of those server{} blocks and more than hundred of deny IP subnet blocks, I'm afraid that the configuration might become to complex and bulky, affecting the server performance.
Is there a better option than including the same list of denied IP's in every server{} block?