Curl 如何通过HTTPS测试特定的负载平衡器实例?

Curl 如何通过HTTPS测试特定的负载平衡器实例?,curl,nginx,https,proxy,dns,Curl,Nginx,Https,Proxy,Dns,我有一组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.1

我有一组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解析的方法可以做到这一点?

您遇到的问题是,您正在设置的主机头正在发送到服务器,但curl没有将其用于SSL验证

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

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

--解析

为特定主机和端口对提供自定义地址。使用此选项,可以使curl请求使用指定的地址,并防止使用正常解析的地址。考虑它是命令行上提供的一种/ETC/主机替代品。 见:

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

curl-v——解析www.example.com:443:10.10.10https://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)

主机文件选项对您有用吗?在docker容器中运行测试怎么样?
$ 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)