

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Mengakhiri HTTPS di EC2 instans Amazon yang menjalankan .NET
<a name="SSLNET.SingleInstance"></a>

[File konfigurasi](ebextensions.md) berikut membuat dan menjalankan PowerShell skrip Windows yang melakukan tugas-tugas berikut:
+ Memeriksa sertifikat HTTPS yang ada yang mengikat ke port 443.
+ Mendapat [sertifikat PFX](configuring-https-ssl.md) dari bucket Amazon S3.
**catatan**  
Tambahkan `AmazonS3ReadOnlyAccess` kebijakan `aws-elasticbeanstalk-ec2-role` untuk mengakses sertifikat SSL di bucket Amazon S3.
+ Mendapat kata sandi dari AWS Secrets Manager.
**catatan**  
Tambahkan pernyataan `aws-elasticbeanstalk-ec2-role` yang memungkinkan `secretsmanager:GetSecretValue` tindakan untuk rahasia yang berisi kata sandi sertifikat
+ Menginstal sertifikat.
+ Mengikat sertifikat ke port 443.
**catatan**  
Untuk menghapus titik akhir HTTP (port 80), masukkan perintah `Remove-WebBinding` di bawah bagian **Hapus pengikatan HTTP** pada contoh.

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

```
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
```

Pada lingkungan instans tunggal, Anda juga harus mengubah grup keamanan instans untuk mengizinkan lalu lintas pada port 443. File konfigurasi berikut mengambil ID grup keamanan menggunakan CloudFormation [fungsi](ebextensions-functions.md) dan menambahkan aturan ke dalamnya.

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

```
Resources:
  sslSecurityGroupIngress: 
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
      IpProtocol: tcp
      ToPort: 443
      FromPort: 443
      CidrIp: 0.0.0.0/0
```

Untuk lingkungan yang seimbang beban, Anda mengonfigurasi penyeimbang beban untuk [meneruskan lalu lintas aman melalui yang tidak tersentuh](https-tcp-passthrough.md), atau [mendekripsi](configuring-https-endtoend.md) dan mengenkripsi ulang untuk enkripsi. end-to-end