---
title: "Cấu hình PowerShell tự động cập nhật chứng chỉ SSL IIS tự động trên Windows Server VPS"
description: "Hướng dẫn tự động gia hạn và gắn chứng chỉ SSL Let's Encrypt cho IIS trên Windows Server VPS bằng PowerShell (Posh-ACME) và win-acme, không còn nỗi lo hết hạn SSL."
canonical: "https://thuecloud.vn/cau-hinh-powershell-tu-dong-cap-nhat-chung-chi-ssl-iis-tu-dong-tren-windows-server-vps"
markdown_url: "https://thuecloud.vn/cau-hinh-powershell-tu-dong-cap-nhat-chung-chi-ssl-iis-tu-dong-tren-windows-server-vps.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:24.378Z"
updated_at: "2026-11-22T16:18:22.184Z"
site: "ThueCloud.Vn"
estimated_tokens: 2246
---
# Cấu hình PowerShell tự động cập nhật chứng chỉ SSL IIS tự động trên Windows Server VPS

> Hướng dẫn tự động gia hạn và gắn chứng chỉ SSL Let's Encrypt cho IIS trên Windows Server VPS bằng PowerShell (Posh-ACME) và win-acme, không còn nỗi lo hết hạn SSL.

- Canonical HTML: https://thuecloud.vn/cau-hinh-powershell-tu-dong-cap-nhat-chung-chi-ssl-iis-tu-dong-tren-windows-server-vps
- Markdown URL: https://thuecloud.vn/cau-hinh-powershell-tu-dong-cap-nhat-chung-chi-ssl-iis-tu-dong-tren-windows-server-vps.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Chuẩn bị môi trường PowerShell và Cài đặt Posh-ACME
- Script PowerShell tự động xin mới / gia hạn và gắn vào IIS Binding
- Thiết lập Task Scheduler tự động kiểm tra gia hạn
- Câu hỏi thường gặp (FAQ)
  - Tại sao xác thực HTTP-01 trên IIS hay bị lỗi 404 tại đường dẫn /.well-known/acme-challenge/?
  - Có cần restart IIS (iisreset) sau khi script cập nhật chứng chỉ SSL mới không?
  - Nên dùng Posh-ACME hay win-acme (wacs.exe)?

Quản trị website ASP.NET hoặc API nội bộ trên **IIS (Internet Information Services)** của [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) chạy Windows Server thường gặp phiền toái mỗi 90 ngày nếu phải xuất file `.pfx` thủ công và gắn lại vào HTTPS Binding. Việc quên gia hạn khiến trình duyệt báo lỗi bảo mật đỏ rực, làm gián đoạn ứng dụng và mất uy tín với khách hàng. Sử dụng **PowerShell kết hợp module `Posh-ACME` (hoặc `win-acme`)** giúp tự động hoàn toàn từ bước xin chứng chỉ Let's Encrypt đến cập nhật Binding trên IIS.

> **Tóm tắt nhanh (TL;DR):**
> - Cài đặt module **Posh-ACME** trực tiếp từ PowerShell Gallery (`Install-Module -Name Posh-ACME`).
> - Hỗ trợ cả xác thực **HTTP-01** (qua thư mục webroot IIS) và **DNS-01** (qua Cloudflare/Route53 API cho chứng chỉ Wildcard `*.yourdomain.com`).
> - Dùng cmdlet `Set-PACertificate` hoặc script PowerShell tự động cập nhật SSL thumbprint vào IIS Binding và kích hoạt Task Scheduler chạy mỗi tuần.
> - *Cập nhật: 11/2026*

## 1. Chuẩn bị môi trường PowerShell và Cài đặt Posh-ACME

Mở PowerShell với quyền Administrator trên Windows Server VPS, bật TLS 1.2 và cài đặt `Posh-ACME` cùng module quản trị IIS:

```powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Posh-ACME -Scope AllUsers -Force
Import-Module WebAdministration
```

| Phương thức xác thực ACME | Yêu cầu mở cổng 80 | Hỗ trợ Wildcard (`*.domain.com`) | Phù hợp nhất cho |
| --- | --- | --- | --- |
| **HTTP-01** (Webroot IIS) | Bắt buộc mở Port 80 | Không | Website IIS công khai đơn lẻ |
| **DNS-01** (Cloudflare API) | Không cần mở Port 80 | Có | Hệ thống nhiều subdomain hoặc API nội bộ |

## 2. Script PowerShell tự động xin mới / gia hạn và gắn vào IIS Binding

Tạo tệp `C:\Scripts\Update-IisSsl.ps1` dưới đây (sử dụng xác thực Webroot cho site tên `Default Web Site` có thư mục gốc `C:\inetpub\wwwroot`):

```powershell
Import-Module Posh-ACME
Import-Module WebAdministration

$Domain = "app.yourdomain.com"
$SiteName = "Default Web Site"
$WebRoot = "C:\inetpub\wwwroot"
$Email = "admin@yourdomain.com"

# Lấy hoặc gia hạn chứng chỉ
$Cert = Get-PACertificate -MainDomain $Domain
if (-not $Cert) {
    $Cert = New-PACertificate $Domain -AcceptTOS -Contact $Email -Plugin WebRoot -PluginArgs @{ WebRoot = $WebRoot }
} else {
    $Renewed = Submit-Renewal -MainDomain $Domain
    if ($Renewed) { $Cert = $Renewed }
}

# Import vào Windows Certificate Store (LocalMachine\My) và cập nhật IIS Binding
if ($Cert) {
    $PfxPass = ConvertTo-SecureString -String $Cert.PfxPass -AsPlainText -Force
    $Imported = Import-PfxCertificate -FilePath $Cert.PfxFile -CertStoreLocation Cert:\LocalMachine\My -Password $PfxPass
    
    $Binding = Get-WebBinding -Name $SiteName -Protocol "https" -Port 443
    if (-not $Binding) {
        New-WebBinding -Name $SiteName -Protocol "https" -Port 443 -HostHeader $Domain -SslFlags 1
        $Binding = Get-WebBinding -Name $SiteName -Protocol "https" -Port 443
    }
    $Binding.AddSslCertificate($Imported.Thumbprint, "My")
}
```

## 3. Thiết lập Task Scheduler tự động kiểm tra gia hạn

Chạy lệnh tạo lịch tự động mỗi ngày lúc 03:00 sáng (`Submit-Renewal` chỉ thực sự gọi Let's Encrypt khi chứng chỉ còn dưới 30 ngày hạn):

```powershell
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File C:\Scripts\Update-IisSsl.ps1"
$Trigger = New-ScheduledTaskTrigger -Daily -At 3:00AM
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName "AutoRenewIisSSL" -Action $Action -Trigger $Trigger -Principal $Principal -Force
```

Để hệ thống Windows Server VPS vận hành trọn vẹn và an toàn, bạn nên kết hợp thêm giải pháp chống dò mật khẩu RDP tại [Cấu hình PowerShell tự động chặn IP dò mật khẩu Remote Desktop trên Windows Server VPS](https://thuecloud.vn/cau-hinh-powershell-tu-dong-chan-ip-do-mat-khau-remote-desktop-tren-windows-server-vps) và sao lưu dữ liệu tự động qua [Cấu hình PowerShell tự động sao lưu cơ sở dữ liệu SQL Server trên Windows Server VPS](https://thuecloud.vn/cau-hinh-powershell-tu-dong-sao-luu-co-so-du-lieu-sql-server-tren-windows-server-vps). Xem thêm giải đáp thắc mắc về cổng mạng tại [trang FAQ](https://thuecloud.vn/faq).

> **Vận hành IIS ổn định trên Windows VPS tại ThueCloud.Vn:**
> **ThueCloud.Vn** cung cấp Cloud VPS KVM Enterprise NVMe tại `vn-hn` (VAT `0%`, SLA `99,9%`, hoàn tiền `07 ngày`) tối ưu cho hệ sinh thái Windows Server, IIS và .NET Core. Bạn có thể bắt đầu ngay với **VPS VN 2** (`78.000đ`/`90.000đ`) hoặc **VPS VN 3** (`139.000đ`/`170.000đ`) để chạy ứng dụng web mượt mà 24/7. Xem chi tiết tại [bảng giá ThueCloud](https://thuecloud.vn/pricing).

## Câu hỏi thường gặp (FAQ)

### Tại sao xác thực HTTP-01 trên IIS hay bị lỗi 404 tại đường dẫn `/.well-known/acme-challenge/`?
IIS mặc định chặn phục vụ các tệp không có phần mở rộng (extensionless files). Bạn cần tạo một tệp `web.config` nhỏ trong thư mục `C:\inetpub\wwwroot\.well-known\acme-challenge\` khai báo `<mimeMap fileExtension="." mimeType="text/plain" />` để IIS trả về tệp xác thực đúng chuẩn.

### Có cần restart IIS (`iisreset`) sau khi script cập nhật chứng chỉ SSL mới không?
Không. Lệnh `$Binding.AddSslCertificate()` cập nhật trực tiếp cấu hình `http.sys` của Windows mà không làm rớt các kết nối hiện tại hay gây downtime cho ứng dụng ASP.NET.

### Nên dùng `Posh-ACME` hay `win-acme` (`wacs.exe`)?
Nếu bạn thích tích hợp sâu vào kịch bản PowerShell có sẵn để quản lý nhiều site tự động theo code, `Posh-ACME` rất linh hoạt. Nếu muốn công cụ dòng lệnh tương tác sẵn có giao diện menu chọn site IIS nhanh gọn, `win-acme` là lựa chọn tuyệt vời.

## References / Sources

- https://learn.microsoft.com/en-us/powershell/module/webadministration/new-webbinding
- https://poshac.me/docs/v4/

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
