Nginx proxy_pass 到 https

mob*_*ios 9 reverse-proxy nginx

我们有: Ubuntu 16.04
nginx 1.10.3

我是 nginx 的新手,需要有关 proxy_pass 到 https 的帮助。
例如,我们在互联网上有客户,他们称之为 url。

https://testapp.mobios.example.com
Run Code Online (Sandbox Code Playgroud)

我想将此流量传递到我的服务器,IP 地址为 192.168.0.10。在这台服务器上,我启用了 ssl 侦听端口 9443。

我们想使用 nginx 作为 reverse_proxy。我的 nginx 配置看起来像。

server {  
  listen 443;
  servername testapp.mobios.example.com;

  location / {
    proxy_pass https://192.168.0.10:9443;
}
}
Run Code Online (Sandbox Code Playgroud)

如果客户端尝试使用https://testapp.mobios.example.com联系 ssl 服务器,他们将一无所获。

我需要的只是将 https 传递给 https。SNI在这里有问题吗?

任何的想法?请帮助ayyoladi

小智 10

server {
    listen 80;
    server_name website.domain.com;
    return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name website.domain.com;

       #Size archive        client_max_body_size 50M;

        ssl_certificate          /etc/letsencrypt/live/mydomain/fullchain.pem;
        ssl_certificate_key      /etc/letsencrypt/live/mydomain/privkey.pem;
        ssl_trusted_certificate  /etc/letsencrypt/live/mydomain/chain.pem;

       location / {
               proxy_set_header   X-Forwarded-For $remote_addr;
               proxy_set_header   Host $http_host;
   1   ===>    proxy_pass         https://website5.domain.ru;
[ OR ]
   2   ===>    proxy_pass         http://192.65.87.4:8020;
       }

}



Run Code Online (Sandbox Code Playgroud)

  • 我知道这是一个旧线程,但我只花了 2 天跟踪类似的错误,它可以很好地代理传递 https 到 google,但它无法在我自己的 HTTPS 服务器上工作。即使我绕过 ssl verify.. 对我来说,错误是 `proxy_set_header Host $http_host;` 将传递我的服务器会拒绝的标头。删除它解决了我的问题。我知道在这个例子中你确实需要主机,因为你指向一个IP。 (2认同)

小智 8

不是直接相同但类似的问题把我带到了这里。

负载均衡到 HTTPS:

Client <- HTTPS -> (decrypt) Load balancer (encrypt) <- HTTPS -> Server
Run Code Online (Sandbox Code Playgroud)

一般来说,thisisayush 答案(http://reinout.vanrees.org/weblog/2017/05/02/https-behind-proxy.html)非常好,它部分解决了我的问题,但添加负载平衡使得它变得更加困难谷歌。

当您创建上游列表时,您必须记住添加端口443

不工作:

upstream myapp2 {
  server 10.0.1.1;
}
Run Code Online (Sandbox Code Playgroud)

在职的:

upstream myapp2 {
  server 10.0.1.1:443;
}
Run Code Online (Sandbox Code Playgroud)

即使您在location https协议中使用(我希望默认指向443):

location / {
  proxy_pass https://myapp2;
}
Run Code Online (Sandbox Code Playgroud)

完整示例:

http {
  upstream myapp2 {
    server 10.0.1.1:443;
  }

  server {
    listen 443;

    ssl_certificate     /etc/nginx/cert.crt;
    ssl_certificate_key /etc/nginx/cert.key;

    ssl on;

    location / {
      proxy_pass https://myapp2;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

答案基于我最终在 thisisayush 评论的帮助下找到的文档:

https://docs.nginx.com/nginx/admin-guide/security-controls/secure-http-traffic-upstream/#complete-example


小智 2

我为我的客户做过一次。您要做的就是在 Nginx 中启用并安装 SSL,而不是在被代理的服务器上。

  • @mobios 在这种情况下,您需要一个 TCP **隧道**。我不确定它与 SSL 的配合效果如何。但是如果你想使用 nginx 来代理 SSL 流量,它需要一个 SSL 证书——代理的本质是它会查看流量并重新封装它,因此它需要 SSL 来做到这一点。 (4认同)
  • 您好,thisisayush,谢谢您的回答。我不想在 nginx 上安装 ssl。我只想将 https 流量从互联网内部传递到服务器。 (3认同)