

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

# .NET을 실행하는 Amazon EC2 인스턴스에서 HTTPS 종료
<a name="SSLNET.SingleInstance"></a>

다음 [구성 파일](ebextensions.md)은 다음 작업을 수행하는 Windows PowerShell 스크립트를 만들고 실행합니다.
+ 포트 443에 바인딩된 기존 HTTPS 인증서 확인
+ Amazon S3 버킷에서 [PFX 인증서](configuring-https-ssl.md) 가져오기
**참고**  
Amazon S3 버킷의 SSL 인증서에 액세스하려면 `aws-elasticbeanstalk-ec2-role`에 `AmazonS3ReadOnlyAccess` 정책을 추가합니다.
+ 암호를 가져옵니다 AWS Secrets Manager.
**참고**  
인증서 암호가 포함된 비밀에 대한 `secretsmanager:GetSecretValue` 작업을 허용하는 문을 `aws-elasticbeanstalk-ec2-role`에 추가합니다.
+ 인증서를 설치합니다.
+ 포트 443에 인증서를 바인딩합니다.
**참고**  
HTTP 엔드포인트(포트 80)를 제거하려면 예제의 **HTTP 바인딩 제거** 섹션 아래에서 `Remove-WebBinding` 명령을 추가합니다.

**Example .ebextensions/https-instance-dotnet.config**  

```
files:
  "C:\\certs\\install-cert.ps1":
    content: |
      import-module webadministration
      ## Settings - replace the following values with your own
      $bucket = "amzn-s3-demo-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의 트래픽을 허용하도록 인스턴스의 보안 그룹도 수정해야 합니다. 다음 구성 파일은 CloudFormation [함수](ebextensions-functions.md)를 사용하여 보안 그룹의 ID를 검색하고 여기에 규칙을 추가합니다.

**Example .ebextensions/https-instance-single.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
```

로드 밸런싱된 환경에서 로드 밸런서가 [안전한 트래픽을 그대로 통과](https-tcp-passthrough.md)시키거나 종단 간 암호화를 위해 [암호 해독과 재암호화](configuring-https-endtoend.md)하도록 구성합니다.