0

My original nginx.conf:

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

My credentials.conf:

set $credentials 'Basic [long_encoded_login_details]';

But this wont work when nginx starts.

  • This should work, what is the error that you get? – Tarun Lalwani Apr 03 '21 at 16:39
  • When I have the credentials hard coded = my iframe on my webapp displays it's contents. When I use the method above: I receive "localhost could not connect" within the iframe. – user8981199 Apr 03 '21 at 16:56
  • Enable debug-mode (find the error_log directive and use the loglevel `debug`) to see the actual requst send to the Backend. This configuration will work. Its workin in my lab. – Timo Stark Apr 04 '21 at 17:15

1 Answers1

0

Using .conf as a file ending will not work in some cases. This should give you an error trying to reload nginx sudo nginx -s reload or nginx -t on configtest. This depends on your nginx.conf. Check if there is any include directive including anything *.conf from a given directory.

use this

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];
        }
    }
}
Timo Stark
  • 2,721
  • 1
  • 10
  • 23
  • I've tried both methods now. Both (in the docker logs) say 2021/04/05 12:49:04 [emerg] 1#1: open() "/etc/nginx/credentials.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:4. I have tried redoing but including the full/relative filepath but it still looks in /etc/nginx rather than the filepath I have stated. – user8981199 Apr 05 '21 at 12:51
  • okay... where do you have the credentials.include file? in /etc/nginx/? If so the include will be `include credentials.conf`. The include is always relative to `/etc7nginx/`. Please check this. – Timo Stark Apr 05 '21 at 16:02