如何将来自Nginx的请求代理到SSL服务器

我的curl请求如下所示:

 curl --header "Authorization: Basic BASE_64" https://example.com --tlsv1 -k 

(我需要明确提供TLS并跳过validation)

它的工作。 我想设置nginx作为中间件和处理远程服务器的身份validation。

 location / { proxy_pass {{ remote_server }}; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Authorization "Basic {{ base64_token }}"; } 

不幸的是,在这些设置下,我得到了403个禁止。 我在做什么不同于curl请求?


我的error.log显示:

 2014/12/20 02:40:12 [error] 15676#0: *13 connect() failed (111: Connection refused) while connecting to upstream, client: MY_OWN_IP, server: _, request: "GET /MY_REQUESTED_ENDPOINT HTTP/1.1", upstream: "https://MY_REMOTE_UPSTREAM", host: "MY_SERVER_IP" 2014/12/20 02:40:24 [info] 15676#0: *15 client timed out (110: Connection timed out) while waiting for request, client: MY_OWN_IP, server: 0.0.0.0:80 

非常重要的是, MY_UPSTREAM只接受来自MY_SERVER_UP连接,这就是为什么我要创build这个中间件。

最后的工作configuration是

 location / { proxy_pass {{ remote_server }}; proxy_set_header Authorization "Basic {{ base64_token }}"; } 

我们不应该通过$host (我们希望我们的中间件是主机)也不是$scheme (我不使用中间件上的SSL,而上游使用)。