运行Python Flask应用程序的Elastic Beanstalk(AWS)的HTTPS。无法获取资源的URL

2024-04-24 11:17:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Flask框架创建了一个小型Python站点。我已经使用ElasticBeanstalk将其上传到AWS,并尝试配置环境以确保启用HTTPS。我以前也这样做过ASP.NET和IIS,但不是Python/Apache。(我对这个“堆栈”非常陌生)。如果我访问底层的elastic beanstalk URL,我可以很好地访问该站点(自己试试)

http://flask-priceline.f8n9uir55a.ap-southeast-2.elasticbeanstalk.com

然而,当我试图访问正确的DNS与HTTPS或HTTP,例如

http://plmonitoring.in-daws.api.net.au/https://plmonitoring.in-daws.api.net.au/

我得到:

无法访问此站点可编程逻辑器件-daws.api.net找不到.au的服务器IP地址。 尝试运行Windows网络诊断。 DNS探测\u完成\u NXDOMAIN

这就是我所做的。我已经在AWS中创建了一个有效的证书。我还在Route 53中设置了相应的记录集/CNAMES,以便我的别名指向我创建的负载平衡器。你知道吗

我已经用一个经典的负载平衡器创建了我的ElasticBeanstalk环境。负载均衡器位于公用子网中,运行web服务器的EC2实例位于专用子网中。(此专有网络是预先存在的,并且配置正确)。我在负载平衡器上创建了以下侦听器:

enter image description here

我通过以下.ebextensions配置文件完成了此操作:

option_settings:
  aws:elb:listener:443:
    SSLCertificateId: arn:aws:acm:ap-southeast-2:xxxxxxxxxxxxx:certificate/xxxxxxxxxxxxxxxxxxxx
    ListenerProtocol: HTTPS
    InstancePort: 80

在我的安全组中还设置了以下内容(我尝试将http80添加为inbound到负载平衡器,并将outbound添加到EC2/inbound到EC2,没有任何更改)。这是入站负载平衡器安全组:

enter image description here

负载平衡器输出:

enter image description here

EC2英寸:

enter image description here

EC2输出:

enter image description here

我还将这个示例添加到.ebextensions文件夹中,希望它能将HTTP重定向到HTTPS,以防用户键入HTTP而不是HTTPS-https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/security-configuration/https-redirect/python/https-redirect-python.config


Tags: httpsawsapihttpnet环境站点ec2