

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# .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 証明書にアクセスするには、`AmazonS3ReadOnlyAccess` ポリシーを `aws-elasticbeanstalk-ec2-role` に追加します。
+ パスワードを から取得します AWS Secrets Manager。
**注記**  
証明書パスワードを含むシークレットの `secretsmanager:GetSecretValue` アクションを許可するステートメントを `aws-elasticbeanstalk-ec2-role` に追加します
+ 証明書をインストールする。
+ ポート 443 に証明書をバインドする。
**注記**  
HTTP エンドポイント (ポート 80) を削除するには、`Remove-WebBinding` コマンドをサンプルの「**HTTP バインディングを削除する**」セクションに含めます。

**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)ことができるようにロードバランサーを設定します。