我们已将 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
中定义的所有用户作为在另一个密码文件中定义的一些其他用户。 IE。像这样的东西(不起作用):
location /x {
# authentication
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd, /etc/nginx/conf.d/.otherhtpasswd;
}
我如何使用 Nginx 实现这一目标?
最佳答案
由于 nginx
不接受多个 auth_basic_user_file
指令,我将创建一个简单的脚本来将两个文件连接成第三个文件。然后使用 auth_basic_user_file
指令引用该文件。然后,您可以将其放入 cron 作业中,或者在每次其中一个文件更改时运行它。
关于nginx - 为 Nginx 中的特定位置附加 auth_basic_user_file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47567895/