amazon-web-services - AWS ELB -> 带有自签名证书的 HTTPS 后端服务器

标签 amazon-web-services nginx amazon-ec2 https amazon-elb

我已经有 HTTPS 来终止我的 AWS ELB 上的外部 HTTPS 连接。我现在正在尝试使用带有自签名证书的 HTTPS 来保护我的 ELB 和我在 EC2 上的后端 NGINX 服务器之间的连接。我关注了the documentation ,但通过 HTTPS 访问服务器会导致 408 HTTP 超时。我似乎无法获得任何调试信息来确定失败的地方。

  • 我已经确认安全组允许 ELB 和 EC2 上的 NGINX 之间的连接。
  • 我已经确认 VPC 允许在 ELB 和 EC2 节点之间路由流量(HTTP 也可以正常工作)。
  • 我已经确认 EC2 节点上的 HTTPS 监听器正在运行(我可以直接点击它而无需前往 ELB。
  • 我创建了一个 PublicKeyPolicyType 类型的 ELB 策略,并关联了我的公钥。
  • 我创建了一个类型为 BackendServerAuthenticationPolicyType 的 ELB 策略,并将其与 PublicKeyPolicyType 关联。
  • 我已将 BackendServerAuthenticationPolicyType 与 ELB 相关联。
  • 我确保 SSLNegotiationPolicyType 支持我在 NGINX 配置中指定的算法和密码。
  • 我在 NGINX 访问日志中看到 HTTP 请求,但没有看到 HTTPS 请求。

  • 有什么方法可以让我获得任何额外的诊断信息来测试这个吗?

    这是我的 ELB 配置:
    $ aws elb describe-load-balancers --load-balancer-name <MY-ELB-NAME>
    
    {
        "LoadBalancerDescriptions": [
            {
                "Subnets": [
                    "<REDACTED>",
                    "<REDACTED>",
                    "<REDACTED>"
                ],
                "CanonicalHostedZoneNameID": "<REDACTED>",
                "VPCId": "<REDACTED>",
                "ListenerDescriptions": [
                    {
                        "Listener": {
                            "InstancePort": 80,
                            "LoadBalancerPort": 80,
                            "Protocol": "HTTP",
                            "InstanceProtocol": "HTTP"
                        },
                        "PolicyNames": []
                    },
                    {
                        "Listener": {
                            "InstancePort": 443,
                            "SSLCertificateId": "<REDACTED>",
                            "LoadBalancerPort": 443,
                            "Protocol": "HTTPS",
                            "InstanceProtocol": "HTTPS"
                        },
                        "PolicyNames": [
                            "ELBSecurityPolicy-2015-05"
                        ]
                    }
                ],
                "HealthCheck": {
                    "HealthyThreshold": 2,
                    "Interval": 30,
                    "Target": "HTTP:80/health",
                    "Timeout": 10,
                    "UnhealthyThreshold": 2
                },
                "BackendServerDescriptions": [
                    {
                        "InstancePort": 443,
                        "PolicyNames": [
                            "MyBackendServerAuthenticationPolicy"
                        ]
                    }
                ],
                "Instances": [
                    {
                        "InstanceId": "<REDACTED>"
                    }
                ],
                "DNSName": "<REDACTED>.us-west-2.elb.amazonaws.com",
                "SecurityGroups": [
                    "<GROUP_ID>"
                ],
                "Policies": {
                    "LBCookieStickinessPolicies": [],
                    "AppCookieStickinessPolicies": [],
                    "OtherPolicies": [
                        "ELBSecurityPolicy-2015-05",
                        "MyBackendServerAuthenticationPolicy",
                        "MyPublicKeyPolicy"
                    ]
                },
                "LoadBalancerName": "<MY-ELB-NAME>",
                "CreatedTime": "2016-03-23T20:58:49.490Z",
                "AvailabilityZones": [
                    "us-west-2a",
                    "us-west-2b",
                    "us-west-2c"
                ],
                "Scheme": "internal",
                "SourceSecurityGroup": {
                    "OwnerAlias": "<REDACTED>",
                    "GroupName": "<GROUP_NAME>"
                }
            }
        ]
    }
    

    这是我的 ELB 政策:
    $ aws elb describe-load-balancer-policies --load-balancer-name <MY-ELB-NAME>
    {
        "PolicyDescriptions": [
            {
                "PolicyAttributeDescriptions": [
                    {
                        "AttributeName": "Reference-Security-Policy",
                        "AttributeValue": "ELBSecurityPolicy-2015-05"
                    },
                    ...
                    {
                        "AttributeName": "Protocol-TLSv1.2",
                        "AttributeValue": "true"
                    },
                    ...
                    {
                        "AttributeName": "ECDHE-RSA-AES128-GCM-SHA256",
                        "AttributeValue": "true"
                    },
                    ...
                ],
                "PolicyName": "ELBSecurityPolicy-2015-05",
                "PolicyTypeName": "SSLNegotiationPolicyType"
            },
            {
                "PolicyAttributeDescriptions": [
                    {
                        "AttributeName": "PublicKeyPolicyName",
                        "AttributeValue": "MyPublicKeyPolicy"
                    }
                ],
                "PolicyName": "MyBackendServerAuthenticationPolicy",
                "PolicyTypeName": "BackendServerAuthenticationPolicyType"
            },
            {
                "PolicyAttributeDescriptions": [
                    {
                        "AttributeName": "PublicKey",
                        "AttributeValue": "<REDACTED>"
                    }
                ],
                "PolicyName": "MyPublicKeyPolicy",
                "PolicyTypeName": "PublicKeyPolicyType"
            }
        ]
    }
    

    这是我的 NGINX 配置:
    worker_processes 10;
    worker_rlimit_nofile 8192;
    events {
      worker_connections  4096;
    }
    
    error_log syslog:server=unix:/dev/log error;
    pid       logs/nginx.pid;
    
    http {
      default_type  application/octet-stream;
    
      log_subrequest on;
      access_log syslog:server=unix:/dev/log,severity=debug extended;
    
      tcp_nodelay    on;
      tcp_nopush     on;
    
      server_tokens off;
    
      upstream api {
        server localhost:8080;
      }
    
      server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        location / {
          # Redirect all other HTTP requests to HTTPS with a 301 Moved Permanently response.
          return 301 https://$host$request_uri;
        }
      }
    
      server {
        listen 443 ssl;
        listen [::]:443 ssl;
    
        ssl_certificate /path/to/ssl.crt;
        ssl_certificate_key /path/to/ssl.key;
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;ECDHE
    
        # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
        ssl_dhparam /path/to/dhparam.pem;
    
        # modern configuration. tweak to your needs.
        # See: https://mozilla.github.io/server-side-tls/ssl-config-generator/
        ssl_protocols TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
        ssl_prefer_server_ciphers on;
    
        add_header Strict-Transport-Security "max-age=15768000; includeSubDomains;";
    
        # Our main location to proxy everything else to the upstream
        # server, but with the added logic for enforcing HTTPS.
        location / {
          proxy_http_version 1.1;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_next_upstream error;
    
          proxy_pass http://api;
        }
      }
    }
    

    我正在使用以下命令生成 key /证书:
    $ openssl genrsa \
      -out /path/to/ssl.key 2048
    $ openssl req \
      -sha256 \
      -new \
      -key /path/to/ssl.key \
      -out /path/to/ssl.csr
    $ openssl x509 \
      -req \
      -days 365 \
      -in /path/to/ssl.csr \
      -signkey /path/to/ssl.key \
      -out /path/to/ssl.crt
    $ openssl dhparam -out /path/to/dhparam.pem 2048
    

    最佳答案

    在 NGINX 配置中添加一些非 EC DHE 密码为我解决了这个问题。我已在 nginx.conf 的 HTTPS 监听器中切换到以下配置:

      # intermediate configuration. tweak to your needs.
      ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
    

    我想放弃所有非 EC DHE 密码,只支持 ECDHE。我怀疑这可以解决问题,因为我正在生成 RSA key /证书而不是 EC key /证书。如果有人知道我如何正确生成 EC key /证书,然后正确提取 EC 公钥以上传到 AWS,请改进我的答案。我尝试生成 EC key /证书,但是当我尝试创建 ELB 公钥策略时,AWS 将其报告为无效公钥。

    关于amazon-web-services - AWS ELB -> 带有自签名证书的 HTTPS 后端服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36182242/

    相关文章:

    javascript - AWS Lambda NodeJs 无法返回响应

    tomcat - modsecurity 有用于 nginx 或 Tomcat 的模块吗?

    linux - 加载共享库时出错 : libsqlplus. 所以:无法打开共享对象文件:没有这样的文件或目录

    java - AWS Lambda : Task timed out

    amazon-web-services - Istio ServiceEntry 用于将多个外部数据库连接到同一个数据库

    amazon-web-services - DynamoDB 中相同分区键的数据分布

    php - nginx 不为 ingress-nginx 后面的 PHP 应用程序提供 JS、CSS 文件

    Nginx 入口 Controller 路径重写不起作用

    node.js - 这是否意味着 Node.js 中存在内存泄漏?

    python - Django Rest 框架中的 POST 方法在 EC2 实例上返回服务器错误 500