【问题标题】:Why aren't my creds being passed into my nginx.conf?为什么我的信用没有被传递到我的 nginx.conf 中?
【发布时间】:2021-06-30 03:50:54
【问题描述】:

我原来的 nginx.conf:

events {}
http {
    server {
    include credentials.conf; 
        listen 80;
        location / {
            proxy_set_header Authorization $credentials;
            proxy_pass [website_of_choice];
        }
    }
}

我的凭据.conf:

set $credentials 'Basic [long_encoded_login_details]';

但这在 nginx 启动时不起作用。

【问题讨论】:

  • 这应该可以,你得到什么错误?
  • 当我对凭据进行硬编码 = 我的 webapp 上的 iframe 显示它的内容。当我使用上述方法时:我在 iframe 中收到“localhost 无法连接”。
  • 启用调试模式(找到error_log指令并使用日志级别debug)查看发送到后端的实际请求。此配置将起作用。它在我的实验室工作。

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


【解决方案1】:

在某些情况下,使用.conf 作为文件结尾将不起作用。这应该会给您一个错误,尝试在 configtest 上重新加载 nginx sudo nginx -s reloadnginx -t。这取决于你的 nginx.conf。检查是否有任何 include 指令,包括给定目录中的任何 *.conf

使用这个

credentials.include

set $credentials 'Basic [long_encoded_login_details]';

nginx.conf

events {}
http {
    server {
    include credentials.include; 
        listen 80;
        location / {
            proxy_set_header Authorization $credentials;
            proxy_pass [website_of_choice];
        }
    }
}

【讨论】:

  • 我现在两种方法都试过了。两者(在 docker 日志中)都说 2021/04/05 12:49:04 [emerg] 1#1: open() "/etc/nginx/credentials.conf" failed (2: No such file or directory) in /等/nginx/nginx.conf:4。我已经尝试重做,但包括完整/相对文件路径,但它仍然在 /etc/nginx 中查找,而不是我所说的文件路径。
  • 好的...你在哪里有 credentials.include 文件?在 /etc/nginx/?如果是这样,包含将是include credentials.conf。包含始终相对于/etc7nginx/。请检查这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-05
  • 1970-01-01
  • 2013-08-20
  • 2019-06-14
  • 2018-09-09
  • 2014-09-21
  • 2023-03-13
相关资源
最近更新 更多