【问题标题】:How to stop nginx from resolving upstream to ip?如何阻止 nginx 将上游解析为 ip?
【发布时间】:2018-10-10 18:43:26
【问题描述】:

我想将 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地址。但是没有主机名,云主机不知道将其站点上的请求重定向到哪里。

只是猜测......因为我也无法使用 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;
  }
 }

【问题讨论】:

    标签: nginx cloud reverse-proxy nginx-reverse-proxy


    【解决方案1】:

    您应该为后端启用 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;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2010-11-04
      • 1970-01-01
      相关资源
      最近更新 更多