Nginx白名单IP和主机名。 否则HTTPauthentication

在Apache上,除非主机名与我们的白名单相匹配,或者访问者的IP与我们的白名单相匹配,否则我们可以为所有开发分支提供http auth。

这就是我们所拥有的:

SetEnvIf Host master.oursite.co GrantAccess SetEnvIf Host 1429-new-checkout.oursite.co GrantAccess allow from 213.141.134.200 allow from 46.159.236.22 

我怎么能在一个需要最less的configuration每次我想添加/删除访问的方式在NginX上完成。

我们有本地和远程开发人员,以及我们需要向客户展示的各种公共网站。 这是我用的。

将一个名为auth.conf的文件包含到您的虚拟主机configuration中

 #auth check - satisfy if ip or key match satisfy any; allow 95.139.104.184/29; allow 95.55.120.28/32; deny all; #auth file auth_basic "closed site"; auth_basic_user_file /etc/nginx/htpasswd; 

一定要创build/ etc / nginx / htpasswd文件

 sudo htpasswd -c /etc/nginx/htpasswd exampleuser 

对于基于主机名的匹配,您可以使用此处介绍的使用此rDNS的第三方模块

 rdns_allow developers\.example\.com;