确保您已正确配置 SSL/TLS/密码设置。如果您的源服务器未与适当的 TLS 密码握手,CloudFront 将断开 HTTPS 连接。
我推荐以下设置:
# Apache
SSLCipherSuite 'ECDHE+AES:@STRENGTH:+AES256'
SSLCipherSuite 'ECDHE+AES:DHE+AES:@STRENGTH:+AES256:kRSA+3DES'
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLProtocol all -SSLv3
SSLHonorCipherOrder on
# Nginx
ssl_ciphers 'ECDHE+AES:@STRENGTH:+AES256';
ssl_ciphers 'ECDHE+AES:DHE+AES:@STRENGTH:+AES256:kRSA+3DES';
ssl_protocols all -SSLv3 -TLSv1 -TLSv1.1;
ssl_protocols all -SSLv3;
ssl_prefer_server_ciphers on;
@STRENGTH 指令将按照强度对密码进行排序。
SSLHonorCipherOrder on (apache) 和 ssl_prefer_server_ciphers on (Nginx) 将确保遵守顺序。
您可以通过在 shell 上运行命令来查看您的 openssl 版本支持的可用密码的完整列表:
$ openssl ciphers -v 'ALL'
您还可以以类似的方式按强度顺序列出上述建议指令的可用密码:
$ openssl ciphers -v 'ECDHE+AES:@STRENGTH:+AES256'
如果您遇到此类问题,我强烈建议您增加 Web 服务器日志的详细程度,尤其是与 SSL 有关的日志。
在 Apache 中,您必须在 conf 文件中使用以下指令来执行此操作
LogLevel debug
以下是可能的 Apache LogLevel 指令列表:
emerg (emergencies - system is unusable)
alert (action must be taken immediately)
crit (critical conditions)
error (error conditions)
warn (warning conditions)
notice (normal but significant condition)
info (informational)
debug (debug-level messages)
trace1 (trace messages)
trace2 (trace messages)
trace3 (trace messages)
trace4 (trace messages)
trace5 (trace messages)
trace6 (trace messages)
trace7 (trace messages, dumping large amounts of data)
trace8 (trace messages, dumping large amounts of data)
一般来说,调试足以让您识别协商问题(可能是密码问题,也可能是证书问题)
CloudFront 无法与您的源服务器成功协商 SSL 的典型反应如下所示:
[ssl:info] [pid 25091] [client xxx.xxx.xxx.xxx:15078] AH01964: Connection to child 1 established (server example.com:443)
[ssl:debug] [pid 25091] ssl_engine_kernel.c(2372): [client xxx.xxx.xxx.xx:15078] AH02043: SSL virtual host for servername example.com found
[ssl:debug] [pid 25091] ssl_engine_io.c(1368): (104)Connection reset by peer: [client xxx.xxx.xxx.xxx:15078] AH02007: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!]
[ssl:info] [pid 25091] [client xxx.xxx.xxx.xxx.15078] AH01998: Connection closed to child 1 with abortive shutdown (server example.com:443)
在这种情况下,Apache 通过“提示:在浏览器中按下停止按钮?!”来解释 CloudFront 断开连接。是的,有点滑稽。
另一方面,CloudFront 可能是一个棘手的野兽。如果您在分配中强制使用 HTTPS 或将 HTTP 定向到 HTTPS,则必须确保 CloudFront 和源服务器之间的通信通过具有有效 SSL 证书的有效 SSL 连接运行。这可能意味着通过 Elastic Load Balancer (ELB) 链接 Amazon ACM 来获取证书。
...或者您也可以通过将 ACM 证书链接到您的发行版来获得所需的结果(确保您列出了顶级域和子域,例如:example.com 和 *.example.com)。这会将 ACM 证书传播到分发中的源/目标,但是,源服务器中的 Apache/Nginx 服务器必须具有有效且有效的 SSL 证书,即使它是由 Letsencrypt/Certbot(我们的其他一些有效的非自签名证书)。确保您在 apache *.conf 设置中配置了完整的链。
您可以阅读有关 502 Bad Gateway 或 502 无法满足请求 from AWS 以及 requiring HTTPS for communication between CloudFront and your custom origin (this may also help) 的更多信息。 This information about ciphers 和 list of supported ciphers on AWS 非常有帮助
其中一些命令也可能有助于调试您的 SSL 情况:
openssl s_client -connect test.example.com:443 -tls1_1
(您可以尝试使用 -tls1_2 、 -tls1_3 或其他协议)
您可能还想尝试使用 http 命令行工具(您可能需要安装它),它会为您提供如下输出:
$ http https://example.com --head
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 251
Content-Type: text/html; charset=iso-8859-1
Date: Mon, 20 Dec 2021 19:20:15 GMT
Location: https://example.com
Server: Apache
Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
Via: 1.1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)
X-Amz-Cf-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==
X-Amz-Cf-Pop: GIG51-C2
X-Cache: Miss from cloudfront
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
祝调试好运,记住:继续深入挖掘,不要放弃,增加日志的详细程度!