简体   繁体   中英

Configure nginx to accept connection from a single host/ip on specific subdomain

I would like to know how to configure nginx to allow access to a single IP, for a subdomain.

Which means, all *.domain.com can be accessed by public, except dev-stg.domain.com

as you might have guessed, I am trying to reserve one subdomain for a pre-production check.

I would recommend using the geo module:

geo $unknown_ip {
    default 1;
    192.0.2.1 0;  # or use CIDR notation
}

server {
    listen 80;
    server_name example.com;

    location / {
        if ($unknown_ip) {
            return 403;
        }
        try_files $uri $uri/ =404;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM