问题描述: 当在AWS Elastic Load Balancer (ELB)上启用SSL/TLS终止时,出现了困惑。 它可能会将完全加密的HTTPS请求解密并将其发送到用户容器上未加密的HTTP连接上。这会在您的安全性方面带来风险。
解决方案: 为了解决此问题,您可以使用以下代码示例中的方法:
示例代码:
在ELB上启用SSL / TLS终止:
frontend_https_listener:
listener_protocol: "HTTPS"
listener_ssl_certificate: "
在应用程序中解释X-Forwarded-Proto:
if (req.http.X-Forwarded-Proto !~ "(?i)https") { return (synth(750, "")); }
将传入的HTTP连接重定向到HTTPS:
frontend_http_listener: listener_protocol: "HTTP" balancer_protocol: "HTTP" balancer_port: "80" rules: - rule_condition: "host-header Matches my.example.com" rule_redirect: protocol: "https" port: "443" query: "" status_code: "HTTP_301" replace_key: "true"