如何使用nginx代理需要authentication的主机?

如何设置一个nginx的proxy_pass指令,这个指令还会包含发送给代理主机的HTTP基本authentication信息?

这是我需要代理的URL的一个例子:

http://username:[email protected]/export?uuid=1234567890 

最终目标是允许1个服务器呈现来自另一个服务器(我们正在代理的那个)的文件而不暴露代理服务器的URI。 我从这里find了Nginx的configuration,现在正确地工作了90%:

Nginx-Fu: X-Accel-Redirect From Remote Servers

我只需要添加HTTP基本身份validation发送到代理服务器

    我前一阵子写了一篇文章。 在这里看到的细节:

    http://shairosenfeld.blogspot.com/2011/03/authorization-header-in-nginx-for.html

    例如:

      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_pass http://6.6.6.6:80; proxy_set_header Authorization "Basic a2luZzppc25ha2Vk"; } 

    “a2luzzppc25ha2Vk”是“king:isnaked”base64编码,所以这将工作

    HTTP://王:[email protected]

    随时查看博客文章的更多细节。

    我用alvosu的答案得到了这个工作,但是我必须在base64string的引号内input“Basic”一词,所以它看起来像这样:

     proxy_set_header Authorization "Basic dGVzdHN0cmluZw=="; 

    设置proxy_set_header授权“USER_AND_PASS”,其中USER_AND_PASS = base64(user:pass)