【问题标题】:How to hide nginx.conf authorization credentials?如何隐藏 nginx.conf 授权凭据?
【发布时间】:2021-06-29 12:10:53
【问题描述】:

为了快速解释,我在 Docker 中运行了一个 nginx 服务器,充当我的 Flask Web 应用程序的反向代理。我的部分配置是使用proxy_set_header Authorization 将一些凭据传递到proxy_pass 网站。

这一切都很好 - 但是,我想将所有这些东西推送到 GitHub,当然不希望我的凭据(无论是否编码)显示出来。

我最好的选择是什么?我能想到的就是有一些类似于 dotenv 的东西,但用于 nginx.conf 文件而不是 .py 文件。

有没有人知道我可以做些什么来传递我的信用但是而不在配置中明确地硬编码它们?

【问题讨论】:

    标签: linux docker nginx nginx-reverse-proxy nginx-config


    【解决方案1】:

    您可以使用另一个配置文件使用 set 使用 NGINX 创建变量并将此文件添加到 gitignore。

    conf.d/creds.include

    set $apiuser "user";
    set $apipass "pass";
    
    

    http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set

    app.conf

    server {
    include conf.d/creds.include;
    ...
    location / {
      proxy_pass ...
      proxy_set_header "Authorization: $apiuser:apipass"
    }
    }
    

    你应该在你的代码库的自述文件中提到这一点,任何人都知道如何使用它。

    【讨论】:

    • 这绝对是最好的主意,但我已经尝试了很多不同的 sytnaxes,但仍然无法工作
    • 请在您的原始帖子中分享您的 nginx 配置。我将使用它作为模板
    • 嘿蒂莫·斯塔克。我在这里被问到这个问题:stackoverflow.com/questions/66933460/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2016-12-26
    相关资源
    最近更新 更多