我正在尝试使用HTTPS部署Elastic Beanstalk应用程序,但是我一直从HTTPS端点收到502错误。我可以正常访问HTTP端点,并且该站点似乎可以正常工作。我仅在HTTPS上看到此错误。我不确定在哪里可以找到错误,但在EC2实例上的任何日志中都没有发现任何相关的内容。我的SSL证书可能有问题吗?我目前正在使用自签名证书进行测试。这是我用来创建资源的CloudFormation模板的相关部分:
Resources:
# VPC and Subnets
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
Tags:
- Key: Name
Value: !Sub "ClimbAssistVpc${ResourceNameSuffix}"
InternetGateway:
Type: AWS::EC2::InternetGateway
VpcGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
SubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2a
CidrBlock: 10.0.0.0/17
MapPublicIpOnLaunch: true
VpcId: !Ref Vpc
SubnetB:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2b
CidrBlock: 10.0.128.0/18
MapPublicIpOnLaunch: true
VpcId: !Ref Vpc
SubnetC:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-west-2c
CidrBlock: 10.0.192.0/18
MapPublicIpOnLaunch: true
VpcId: !Ref Vpc
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'Security group for Climb Assist Elastic Beanstalk application'
SecurityGroupIngress:
- CidrIp: '0.0.0.0/0'
IpProtocol: tcp
FromPort: 80
ToPort: 80
- CidrIp: '0.0.0.0/0'
IpProtocol: tcp
FromPort: 22
ToPort: 22
SecurityGroupEgress:
- CidrIp: '0.0.0.0/0'
IpProtocol: -1 # all protocols
ToPort: 0
FromPort: 65535
VpcId: !Ref Vpc
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref Vpc
Route:
Type: AWS::EC2::Route
DependsOn: VpcGatewayAttachment
Properties:
RouteTableId: !Ref RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
SubnetARouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref SubnetA
SubnetBRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref SubnetB
SubnetCRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref SubnetC
# Elastic Beanstalk environments
EBApplication:
Description: The AWS Elastic Beanstalk application, which is a container used to deploy the correct application configuration.
Type: AWS::ElasticBeanstalk::Application
Properties:
ApplicationName: !Sub '${ProjectId}app${ResourceNameSuffix}'
Description: The name of the AWS Elastic Beanstalk application to be created for this project.
EBApplicationVersion:
Description: The version of the AWS Elastic Beanstalk application to be created for this project.
Type: AWS::ElasticBeanstalk::ApplicationVersion
Properties:
ApplicationName: !Ref 'EBApplication'
Description: The application version number.
SourceBundle: 'target/ROOT'
EBConfigurationTemplate:
Description: The AWS Elastic Beanstalk configuration template to be created for this project, which defines configuration settings used to deploy different versions of an application.
Type: AWS::ElasticBeanstalk::ConfigurationTemplate
Properties:
ApplicationName: !Ref 'EBApplication'
Description: The name of the sample configuration template.
OptionSettings:
- Namespace: aws:elasticbeanstalk:environment
OptionName: EnvironmentType
Value: LoadBalanced
- Namespace: aws:elasticbeanstalk:environment
OptionName: ServiceRole
Value: !Ref 'EBTrustRole'
- Namespace: aws:elasticbeanstalk:healthreporting:system
OptionName: SystemType
Value: enhanced
SolutionStackName: !Ref 'SolutionStackName'
EBEnvironment:
Description: The AWS Elastic Beanstalk deployment group where the application is deployed, which is made up of the Amazon EC2 Linux instances launched for this project.
Type: AWS::ElasticBeanstalk::Environment
Properties:
ApplicationName: !Ref 'EBApplication'
EnvironmentName: !Ref 'EBApplication'
CNAMEPrefix:
Fn::Sub: "${ProjectId}${ResourceNameSuffix}"
Description: The application to be deployed to the environment.
TemplateName: !Ref 'EBConfigurationTemplate'
VersionLabel: !Ref 'EBApplicationVersion'
OptionSettings:
- Namespace: aws:autoscaling:launchconfiguration
OptionName: IamInstanceProfile
Value: !Ref 'EBInstanceProfile'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: InstanceType
Value: !Ref 'InstanceType'
- Namespace: aws:autoscaling:launchconfiguration
OptionName: EC2KeyName
Value: !Ref 'KeyPairName'
- Namespace: aws:ec2:vpc
OptionName: VPCId
Value: !Ref Vpc
- Namespace: 'aws:ec2:vpc'
OptionName: Subnets
Value:
Fn::Join:
- ','
- - !Ref SubnetA
- !Ref SubnetB
- !Ref SubnetC
- Namespace: 'aws:autoscaling:launchconfiguration'
OptionName: SecurityGroups
Value: !Ref SecurityGroup
- Namespace: 'aws:ec2:vpc'
OptionName: AssociatePublicIpAddress
Value: 'true'
- Namespace: aws:elasticbeanstalk:environment
OptionName: LoadBalancerType
Value: application
- Namespace: aws:elbv2:listener:443
OptionName: DefaultProcess
Value: https
- Namespace: aws:elbv2:listener:443
OptionName: ListenerEnabled
Value: 'true'
- Namespace: aws:elbv2:listener:443
OptionName: Protocol
Value: HTTPS
- Namespace: aws:elbv2:listener:443
OptionName: SSLCertificateArns
Value: arn:aws:acm:us-west-2:172776452117:certificate/724f70c2-01bd-415d-adbc-a5167d4a6fad
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Port
Value: '443'
- Namespace: aws:elasticbeanstalk:environment:process:https
OptionName: Protocol
Value: HTTPS
我还是Elastic Beanstalk和EC2的新手,因此能提供任何帮助。谢谢!
答案 0 :(得分:1)
由于@NeverBe,我得以解决此问题。我正在将负载均衡器的端口443上的HTTPS侦听器映射到实例上的端口443。相反,我需要将负载均衡器上的端口443路由到实例上的端口80。
答案 1 :(得分:0)
我的NodeJ和ExpressJ后端微服务也面临着同样的问题。当我尝试访问端点时发现了这一点。通过将其与AWS CodeBuild和GitHub链接,我在Elastic Beanstalk中更新了代码。我注意到部署阶段运行良好,没有任何错误。经过一番调查后,发现缺少在实例中运行我的服务器的命令,即npm start
或node <main_server_file_name>.js
。一切都顺利进行了。您可以在环境内的Configuration > Software > Command
中更新此命令。