nginx - 为 Nginx 中的特定位置附加 auth_basic_user_file

标签 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 中定义的所有用户作为在另一个密码文件中定义的一些其他用户。 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/

相关文章:

node.js - NGINX、边缘、HAPRoxy

docker - 隐藏 NGINX Docker 容器公开的 URL 中的端口号

django - 使用AWS elastic beanstalk(使用nginx + Gunicorn)部署django时出现ERR_CONNECTION_TIMED_OUT

nginx - 如何配置 nginx 以将其 error.log 文件放在我有写权限的地方?

php - 索引 PHP 下载而不是执行它

php - 使用node.js Node http服务器而不是php/ruby​​/etc + nginx有什么优势?

Nginx - 使用/子文件夹重定向反向代理 Ghost 博客

vue.js - 使用 connect-history-api-fallback' ,但不知道如何在 vuejs 中实现

ruby-on-rails - 如何消除 ActionController::UnknownHttpMethod 错误?

php - 无法通过 HTTPS 访问 SOAP Web 服务