发布于 2016-02-26  71 次阅读

How can I setup an nginx proxy_pass directive that will also include HTTP Basic authentication information sent to the proxy host?

This is an example of the URL I need to proxy to:


The end goal is to allow 1 server present files from another server (the one we're proxying to) without exposing the URI of the proxy server. I have this working 90% correct now from following the Nginx config found here:

I just need to add in the HTTP Basic authentication to send to the proxy server


I did a writeup on this a while ago. See the details here:

For example:

 location / {
    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_set_header Authorization "Basic a2luZzppc25ha2Vk";

"a2luZzppc25ha2Vk" is "king:isnaked" base64 encoded, so that would work for


Feel free to check out blog post for more details.