[英]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. 我想知道如何配置nginx以允许访问子域的单个IP。
Which means, all *.domain.com
can be accessed by public, except dev-stg.domain.com
这意味着,除dev-stg.domain.com
之外,所有*.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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.