【问题标题】:How do I test an specific load balancer instance over HTTPS?如何通过 HTTPS 测试特定的负载均衡器实例?
【发布时间】:2018-02-07 09:16:51
【问题描述】:

我有一组 Nginx 服务作为单个地址的负载平衡器,比如说www.example.com。我想要一个单独针对这些机器的测试套件,而不是像直接访问地址那样通过 DNS 负载平衡。

当我尝试在 curl 中做类似的事情时,我得到:

 $ curl -H "Host: www.example.com" -v  https://10.10.10.10/                         
*   Trying 10.10.10.10...
* Connected to 10.10.10.10 (10.10.10.10) port 443 (#0)
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt
* found 697 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384
*    server certificate verification OK
*    server certificate status verification SKIPPED
* SSL: certificate subject name (www.example.com) does not match target host name '10.10.10.10'
* Closing connection 0
curl: (51) SSL: certificate subject name (www.example.com) does not match target host name '10.10.10.10'

我知道10.10.10.10 不是同名,但我想指示该工具相信它是(因为我知道它是,这些都是服务于同一个域的负载平衡器)。

有什么方法可以做到不涉及处理 DNS 解析?

【问题讨论】:

  • 主机文件选项是否适合您?
  • 另外,如何在 docker 容器中运行测试?

标签: curl nginx https proxy dns


【解决方案1】:

您遇到的问题是因为您设置的 Host 标头正在发送到服务器,但 curl 没有使用它进行 SSL 验证。

您可以在 curl 输出中看到这一点,注意“已连接到 10.10.10.10”:

 $ curl -H "Host: www.example.com" -v  https://10.10.10.10/                         
*   Trying 10.10.10.10...
* Connected to 10.10.10.10 (10.10.10.10) port 443 (#0)

您可能正在寻找 --resolve 标志:

--解析<host:port:address>

为特定主机和端口对提供自定义地址。使用它,您可以使 curl 请求使用指定的地址,并防止使用其他正常解析的地址。将其视为命令行中提供的一种 /etc/hosts 替代方案。

见:curl man page

考虑到这一点,您可能想尝试一下:

curl -v --resolve www.example.com:443:10.10.10.10 https://www.example.com

这应该在输出中表明 curl 现在正在使用主机名,因此允许验证证书主体名称:

$ curl -v --resolve www.example.com:443:10.10.10.10 https://www.example.com
* Added www.example.com:443:10.10.10.10 to DNS cache
* About to connect() to www.example.com port 443 (#0)
*   Trying 10.10.10.10...
* Connected to www.example.com (10.10.10.10) port 443 (#0)

【讨论】:

    猜你喜欢
    • 2015-05-25
    • 2016-08-13
    • 2021-01-04
    • 2018-10-27
    • 1970-01-01
    • 2017-02-19
    • 2016-05-12
    • 2015-11-13
    • 2014-02-12
    相关资源
    最近更新 更多