在Nginx中为特定位置附加auth_basic_user_file

时间:2017-11-30 07:19:14

标签: nginx

我们已将Nginx配置为对整个网站使用基本身份验证:

location / {
    # ... More stuff goes here ...

    # authentication
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
}

现在在一个特定的位置,比如/x,我想允许/etc/nginx/conf.d/.htpasswd中定义的所有用户以及另一个密码文件中定义的其他用户。即这样的事情(不起作用):

location /x {  
    # authentication
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/conf.d/.htpasswd, /etc/nginx/conf.d/.otherhtpasswd;
}

如何使用Nginx实现这一目标?

1 个答案:

答案 0 :(得分:1)

由于nginx不接受auth_basic_user_file指令的多个,我会创建一个简单的脚本将两个文件连接成第三个文件。然后使用auth_basic_user_file指令引用该文件。然后,您可以将其放在cron作业中,或者只在其中一个文件发生更改时运行它。

相关问题