Friday, September 9, 2016

Apply location directives to subdomains and sub-subdomains on NGINX

I'm trying to setup a site on NGINX so the second level domain is visible publicly, but access to subdomains is restricted. Basically a dev.domain.com should be restricted to my IP, and staging.domain.com is restricted to http authentication. I also want the same restrictions applied to all sub-subdomains of those subdomains.



The server_name for each subdomain is set with the special wildcard, which I thought would effect all domains down the line, (see below). so I set location directives in the server block for each subdomain; allow/deny for server_name .dev.domain.com and auth_basic for server_name .staging.domain.com.



It's working great for the subdomains, but I'd like to have those directives also apply to all sub-subdomains (i.e.site1.dev.domain.com). Right now I have to add the directives to each sub-subdomain individually.



How do I get those directives applied to all sub-subdomains?




Here's the server block setup for staging.domain.com



server {
listen 80;
listen [::]:80;
server_name .staging.domain.com;
root /home/forge/staging.domain.com/public;

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...