AWS Beanstalk单实例环境中的http到https url

时间:2019-02-04 12:16:37

标签: node.js amazon-web-services amazon-ec2 amazon-elastic-beanstalk

我在NodeJS/Express上部署了AWS Beanstalk应用。当前配置为:

Environment type: single instance
EC2 instance type: t2.micro
Node.js version: 10.15.0
No load balancer
Proxy server : Nginx

部署后,它会给我一个URL http://<app-name>.<server-location>.elasticbeanstalk.com/

我使用URL Postman测试(使用http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate)我的身份验证API,它为我提供了200 OK的状态代码,并且运行正常。

当我使用HTTPS而不是HTTP时,它无法按预期运行。在邮递员中,我得到以下错误:

There was an error connecting to https://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate

我将前端部署在netlify上,当我从Web应用程序触发相同的请求时,它给我以下错误:

The page at 'https://<app-name>.netlify.com/login' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate'. This request has been blocked; the content must be served over HTTPS.

我了解,由于我的请求来自https,因此我需要将后端配置为具有https侦听器。我不确定如何在没有负载均衡器且我的env类型是单个实例的AWS Beanstalk中完成此操作。

我是AWS的新手。感谢您的帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将.ebextension配置文件添加到:

  • 在您的安全组中允许443流量
  • 安装ssl软件包
  • 将证书从应用程序包复制到ssl目录。 (可以在证书管理器中创建证书)或将其粘贴到配置文件中
  • 编辑nginx配置

这里是一个例子 https://edwardsamuel.wordpress.com/2015/07/17/enable-https-and-http-redirect-on-aws-elastic-beanstalk/