.NET을 실행하는 Amazon EC2 인스턴스에서 HTTPS 종료 - AWS Elastic Beanstalk

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

.NET을 실행하는 Amazon EC2 인스턴스에서 HTTPS 종료

다음 구성 파일은 다음 작업을 수행하는 Windows PowerShell 스크립트를 만들고 실행합니다.

  • 포트 443에 바인딩된 기존 HTTPS 인증서를 확인합니다.

  • Amazon S3 버킷에서 PFX 인증서를 가져옵니다.

    참고

    Amazon S3 버킷의 SSL 인증서에 aws-elasticbeanstalk-ec2-role 액세스하기 위한 AmazonS3ReadOnlyAccess 정책을 에 추가합니다.

  • 에서 비밀번호를 가져옵니다AWS Secrets Manager.

    참고

    인증서 비밀번호가 포함된 비밀번호에 대한 secretsmanager:GetSecretValue 작업을 허용하는 명령문을 추가하십시오. aws-elasticbeanstalk-ec2-role

  • 인증서를 설치합니다.

  • 인증서를 포트 443에 바인딩합니다.

    참고

    HTTP 엔드포인트(포트 80)를 제거하려면 예제의 HTTP 바인딩 제거 섹션 아래에서 Remove-WebBinding 명령을 추가합니다.

예 .ebextensions/ .config https-instance-dotnet
files: "C:\\certs\\install-cert.ps1": content: | import-module webadministration ## Settings - replace the following values with your own $bucket = "DOC-EXAMPLE-BUCKET" ## S3 bucket name $certkey = "example.com.pfx" ## S3 object key for your PFX certificate $secretname = "example_secret" ## AWS Secrets Manager name for a secret that contains the certificate's password ## # Set variables $certfile = "C:\cert.pfx" $pwd = Get-SECSecretValue -SecretId $secretname | select -expand SecretString # Clean up existing binding if ( Get-WebBinding "Default Web Site" -Port 443 ) { Echo "Removing WebBinding" Remove-WebBinding -Name "Default Web Site" -BindingInformation *:443: } if ( Get-Item -path IIS:\SslBindings\0.0.0.0!443 ) { Echo "Deregistering WebBinding from IIS" Remove-Item -path IIS:\SslBindings\0.0.0.0!443 } # Download certificate from S3 Read-S3Object -BucketName $bucket -Key $certkey -File $certfile # Install certificate Echo "Installing cert..." $securepwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText $cert = Import-PfxCertificate -FilePath $certfile cert:\localMachine\my -Password $securepwd # Create site binding Echo "Creating and registering WebBinding" New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https New-Item -path IIS:\SslBindings\0.0.0.0!443 -value $cert -Force ## Remove the HTTP binding ## (optional) Uncomment the following line to unbind port 80 # Remove-WebBinding -Name "Default Web Site" -BindingInformation *:80: ## # Update firewall netsh advfirewall firewall add rule name="Open port 443" protocol=TCP localport=443 action=allow dir=OUT commands: 00_install_ssl: command: powershell -NoProfile -ExecutionPolicy Bypass -file C:\\certs\\install-cert.ps1

단일 인스턴스 환경에서 포트 443의 트래픽을 허용하도록 인스턴스의 보안 그룹도 수정해야 합니다. 다음 구성 파일은 AWS CloudFormation 함수를 이용해 보안 그룹의 ID를 검색하고, 거기에 규칙을 추가합니다.

예 https-instance-single.ebextensions/ .config
Resources: sslSecurityGroupIngress: Type: AWS::EC2::SecurityGroupIngress Properties: GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]} IpProtocol: tcp ToPort: 443 FromPort: 443 CidrIp: 0.0.0.0/0

부하가 분산된 환경에서는 보안 트래픽을 그대로 전달하거나 암호화를 위해 복호화 후 재암호화하도록 로드 밸런서를 구성합니다. end-to-end