AWS 实例更改为 https

AWS instance change to https

我们现在使用 AWS 来设置我们的网站,我们最近正在尝试设置一个页面,允许我们的客户向我们发送电子邮件。我们设置了一个 EC2 实例作为电子邮件服务器,但它 运行s 在 HTTP 上。由于我们的网站在 HTTPS 上运行,ajax 无法发送 HTTP 消息,我们必须在 HTTPS 上创建 EC2 实例 运行,但我不知道该怎么做。

$.ajax({
    type: "POST",
    url: "https://ec2-*-*-*-*.*.compute.amazonaws.com/send",
    contentType: "application/json; charset=utf-8",
    beforeSend: function(request) {
        request.setRequestHeader("Access-Control-Allow-Origin", "*");
        request.setRequestHeader("Access-Control-Allow-Method", "POST");
    },
    async: true,
    data: JSON.stringify({
        "name": name,
        "email": email,
        "message": message
    }),
    traditional: true,
    error: function(xhr, status, error) {
        var errorMessage = xhr.status + ': ' + xhr.statusText
        alert('Error - ' + errorMessage);
    },
    success: function(result) {
        alert(" Good link");
    }
});

通常有三种方法可用于为您的实例设置 SSL。

  1. 在您的 EC2 前面设置一个 load balancer (LB)。为此,您需要自己的自定义域。拥有域后,您可以从 AWS ACM 获得免费的 public SSL 证书并轻松将其部署在 LB 上。使用 LB,您的应用程序将使用 HTTPS 连接到 LB。 LB 将在 AWS 内部网络中将流量作为 HTTP 转发到实例。

  2. 在您的实例上手动设置有效的 public SSL 证书。为此 AWS ACM can't be used as in step 1, thus you need to get the SSL cert from a third party (not AWS). A popular choice is https://letsencrypt.org/ with https://certbot.eff.org/。在实例上安装 SSL 通常需要设置反向代理,例如 nginx。顺便说一句,Whosebug 将 letsencyrpt 用于其自己的 SSL 证书。

  3. 在您的 EC2 实例前面设置一个 CloudFront (CF) distribution。您可以在 CF 发行版上使用带有 ACM SSL 证书的自定义域,或者您可以使用默认的 CF 端点,它也是 HTTPs。但是,这里的问题是 CF 和您的实例之间的流量将是跨互联网的 HTTP,这存在 安全风险 。要解决此问题,您必须使用步骤 1 或 2 为 HTTP 设置有效的 SSL 证书。