Mau*_*res 2 dns https proxy curl nginx
我有一组 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'
Run Code Online (Sandbox Code Playgroud)
我知道10.10.10.10不是同一个名字,但我想指示工具相信它(因为我知道它是,这些都是服务于同一个域的负载平衡器)。
有什么方法可以不涉及处理 DNS 解析?
您遇到的问题是因为您设置的 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)
Run Code Online (Sandbox Code Playgroud)
您可能正在寻找 --resolve 标志:
- 解决
<host:port:address>为特定主机和端口对提供自定义地址。使用它,您可以使 curl 请求使用指定的地址,并防止使用其他正常解析的地址。将其视为命令行上提供的一种 /etc/hosts 替代方案。
请参阅:curl 手册页
考虑到这一点,您可能想尝试:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4421 次 |
| 最近记录: |