G
G
goshva2018-09-07 19:22:35
Nginx
goshva, 2018-09-07 19:22:35

How to wrap a proxied request to api in auth_basic (embed login and password b64)?

Nginx has to proxy the request with api. But on the api server authorization login password( auth_basic).
I use for early development - security is not important I
used this setting (does not help - it still asks for a password):

upstream app_db2{
    server 192.168.1.66:8890;
    keepalive 16;
}

server {
#   listen 80;
    server_name db2-dev.com;
    access_log /var/log/nginx/db2.log;
  location /api {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://dev1.com/api/v0.1;
    proxy_set_header Authorization "Basic  ***"; #*** -логин:пароль в  base64
#   default_type application/json;
#   return 200 '{"code":"1", "message": "Unknown Error"}';
   }
  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://app_db2/;
    proxy_redirect off;
   }

Tell me the correct config

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
O. J, 2018-09-07
@OrlovEvgeny

Perhaps you specified
the wrong base64 encoding Run user:pass in the console - replace this hash with your own And add a header to debug
proxy_pass_header Authorization;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question