1

我想将 nginx 配置为反向代理,以将 HTTP 请求转发到外部 Cloud-API。这个 nginx 但我收到了拒绝连接错误。

 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"

当然,我用 0.0.0.0 替换了上面(外部云)的 ip

但我认为这就是问题所在。nginx解析云主机的ip,将upstream url替换为ip地址。但是没有主机名,cloudhost 不知道将其站点上的请求重定向到哪里。

只是猜测....因为我也无法使用 curl 或 postman 向端点(以 ip 作为主机)发起请求。但是使用 url 它可以工作。

我的 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;
  }
 }
4

1 回答 1

5

您应该为后端启用 SNI。

从 nginx 1.7.0 开始,这是可能的:http: //nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_server_name

proxy_ssl_server_name on;

于 2018-05-30T12:49:15.210 回答