为什么我的凭据没有传递到我的 nginx.conf 中?

时间:2021-04-03 16:29:56

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

我原来的nginx.conf:

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

我credentials.conf:

set $credentials 'Basic [long_encoded_login_details]';

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

1 个答案:

答案 0 :(得分:0)

使用 .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];
        }
    }
}