6

If I have a number of virtual hosts in the sites-enabled folder, how can I have a common whitelist for all of them?

Aka each one has this block

    allow 127.0.0.1;
    allow 192.168.0.0/16;
    allow x.x.x.x;
    deny all;

How can I have that apply to all the virtual hosts by default, instead of having to write it for every subdomain?

1
  • You may also put your global restrictions in the http section of the /etc/nginx/nginx.conf file. Feb 10 '20 at 14:57
8

Use include

eg put the following text in the file /etc/nginx/shared-configs/whitelist.conf

allow 127.0.0.1;
allow 192.168.0.0/16;
allow x.x.x.x;
deny all;

in the file /etc/nginx/sites-enabled/site1.conf

server {
  server_name example.com;
  include /etc/nginx/shared-configs/whitelist.conf;
}

in the file /etc/nginx/sites-enabled/site2.conf

server {
  server_name site2.example.com;
  include /etc/nginx/shared-configs/whitelist.conf;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.