使用 Ubuntu 16.04,curl
版本 7.47.0
我正在嘗試調試 SSL 證書問題,並在使用curl
.當我剛跑步時:
ubuntu@ip-172-30-0-81:~$ curl https://myapp.com/hello
curl: (51) SSL: certificate subject name (cloud.mynameserver.com) does not match target host name 'myapp.com'
但是,當我附加標誌時-v
:
ubuntu@ip-172-30-0-81:~$ curl -v https://myapp.com/hello
* Trying {IP REDACTED}...
* Connected to myapp.com ({IP REDACTED}) port 443 (#0)
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt
* found 692 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
* common name: myapp.com (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: CN=myapp.com
* start date: Sat, 31 Dec 2016 22:57:00 GMT
* expire date: Fri, 31 Mar 2017 22:57:00 GMT
* issuer: C=US,O=Let's Encrypt,CN=Let's Encrypt Authority X3
* compression: NULL
* ALPN, server accepted to use http/1.1
> GET /hello HTTP/1.1
> Host: myapp.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.10.0 (Ubuntu)
< Date: Sat, 21 Jan 2017 00:25:15 GMT
< Content-Type: application/json
< Transfer-Encoding: chunked
< Connection: keep-alive
< Strict-Transport-Security: max-age=63072000; includeSubdomains
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
<
* Connection #0 to host myapp.com left intact
{"message": "Hello World"}
請注意最後的{"message": "Hello World"}
是預期的回應。
在詳細模式下運行時,為什麼curl
在 SSL 憑證詳細資訊的信任方面表現不同?man
據我所知,頁面中沒有指定這一點。
答案1
您似乎有兩個不同的A
(或AAAA
對於 IPv6)記錄具有相同的主機名稱。當主機名稱有多個記錄時,這會導致該主機名稱的每次查找以循環方式傳回不同的 IP 位址。
當您交替使用和不使用詳細模式的請求時,IP 位址也會交替,導致非詳細請求到達錯誤的 IP 位址,而詳細要求到達正確的 IP 位址。這就是為什麼根據以下內容正確的證書出現在詳細地址中
subject: CN=myapp.com
行,而非詳細地址的錯誤中給出了不同的證書。
正確的解決方法是刪除不正確的A
記錄,以便僅顯示配置為提供內容服務的網路伺服器的位址。