bgeissler
bgeissler

Reputation: 88

How to stop nginx from resolving upstream to ip?

i want to configure a nginx as a reverse proxy to forward HTTP Requests to a external Cloud-API. This nginx But i got a Connection refused error.

 29 09:19:02 [error] 7#7: *2 connect() failed (111: Connection refused) while connecting to upstream, client: x.x.x.x, server: 10.0.2.2, request: "GET /apiv1/endpoint HTTP/1.1", upstream: "https://0.0.0.0:443/apiv1/endpoint", host: "localhost:8080"

Of Course i replaced the ip above (of the external cloud) with 0.0.0.0

But i think that's the problem. nginx resolves the ip of the cloud host and replaced the upstream url with the ip address. But without the hostname, the cloudhost do not know where to redirect the request on their site to.

Just guessing.... Cause i can't fire the request to the endpoint (with ip as host) with curl or postman as well. But with url it works.

My nginx.conf

upstream cloudapi {
   here-comes-the-cloud-url.com:443;
}

server {
  listen 8080 default_server;
  server_name localhost; # 

  location ^~ /apiv1/ {
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection 'upgrade';
     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_cache_bypass $http_upgrade;

     proxy_pass https://cloudapi$uri;
  }
 }

Upvotes: 5

Views: 6325

Answers (1)

unNamed
unNamed

Reputation: 1019

You should enable SNI for the backend.

From nginx 1.7.0 this is possible: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name

proxy_ssl_server_name on;

Upvotes: 6

Related Questions