win‐acme를 사용해 무료 SSL 인증서 생성 갱신 자동화하기 - waegari/waegari.github.io GitHub Wiki
- ACME: Automated Certificate Management Environment
win-acme(Windows ACME Simple)는 Windows 환경에서 Let's Encrypt와 같은 ACME 프로토콜을 지원하는 인증 기관에서 무료 SSL/TLS 인증서를 획득하고 관리하기 위한 도구입니다. 이 매뉴얼에서는 win-acme를 사용하여 웹 서버(특히 NGINX)에 SSL 인증서를 설정하는 방법을 설명합니다.
-
도메인 소유권 확인 (Challenge):
- win-acme는 Let's Encrypt 서버에 인증서 발급 요청을 보냅니다.
- Let's Encrypt는 도메인 소유권을 확인하기 위해 challenge 파일을 요청합니다.
- 이 과정에서, http-01(웹 서버에 특정 파일 생성) 방식, DNS 방식 등을 사용할 수 있습니다. (이 매뉴얼에서는 http-01 방식을 선택)
- win-acme는
.well-known/acme-challenge/
경로에 challenge 파일을 생성합니다. - Let's Encrypt 서버는 해당 도메인의 특정 URL(예:
http://example.com/.well-known/acme-challenge/token
)에 접속하여 파일을 확인합니다.
-
인증서 생성 및 설치:
- 소유권 확인이 완료되면 Let's Encrypt에서 인증서를 발급합니다.
- win-acme는 발급된 인증서를 지정된 경로에 저장합니다.
- 인증서 설치 후 지정된 스크립트(예: NGINX 재시작)를 실행합니다.
-
작업 스케줄러를 통한 갱신:
- win-acme는 작업 스케줄러에 갱신 작업을 등록합니다.
- 일반적으로 만료 30일 전에 자동 갱신이 시도됩니다.
- 갱신 작업은 기존과 동일한 도메인 소유권 확인 과정을 수행합니다.
-
갱신 후 작업 자동화:
- 인증서가 갱신되면 사전 작성한 스크립트(예:
restart-nginx.bat
, 아래에서 설명)가 자동으로 실행되도록 설정할 수 있습니다. - 이 스크립트를 통해 NGINX 서비스를 재시작함으로써 갱신된 인증서를 적용할 수 있습니다.
- 인증서가 갱신되면 사전 작성한 스크립트(예:
-
Windows Server OS에서:
- win-acme 디렉토리에
.well-known/acme-challenge
및Logs
폴더 생성 - 인증서 저장을 위한 디렉토리 생성 (예:
C:\nginx\certs\www.example.com
) - 갱신 자동화를 위한 작업 스케줄러 설정
- 인증서 갱신 후 NGINX 재시작을 위한 스크립트 준비(예:
restart-nginx.bat
)
- win-acme 디렉토리에
-
nginx.conf에서:
- Let's Encrypt 검증 요청을 위한 location 블록 설정
- 인증서 파일 경로 설정
- win-acme 프로그램 설치 (C:\Tools\win-acme 디렉토리에 설치됨)
- win-acme 디렉토리에
.well-known\acme-challenge
폴더 생성- 이 폴더는 Let's Encrypt의 http-01 방식 도메인 소유권 확인에 필요합니다
- 인증서 저장을 위한 디렉토리 생성 (예:
C:\nginx\certs\[도메인명]
) - NGINX와 같은 웹 서버 설치 및 구성
- 관리자 권한이 있는 계정
- NGINX 재시작을 위한 배치 스크립트 생성 (자세한 내용은 아래 참조)
win-acme로 인증서를 발급받기 전에 NGINX를 올바르게 구성해야 합니다. Let's Encrypt의 검증 과정을 방해하지 않도록 다음 설정을 nginx.conf에 추가해야 합니다.
HTTP(80) 및 HTTPS(443) 서버 블록에서 다음 위치 블록을 설정합니다:
server {
listen 80;
server_name example.com www.example.com;
...
# Let's Encrypt 검증 경로 - 최상위 priority로 설정
location ^~ /.well-known/acme-challenge/ {
root C:/Tools/win-acme;
default_type text/plain;
# SPA 리다이렉트를 방지하기 위한 설정
try_files $uri =404; # 파일이 없으면 404 반환, index.html로 리다이렉트하지 않음
}
...
# 다른 모든 요청은 HTTPS로 리다이렉트
location / {
return 301 https://$host$request_uri;
}
...
}
server {
listen 443 ssl;
server_name example.com www.example.com;
...
# SSL 인증서 경로 (인증서 발급 후 설정)
# ssl_certificate C:/nginx/certs/www.example.com/www.example.com-chain.pem;
# ssl_certificate_key C:/nginx/certs/www.example.com/www.example.com-key.pem;
...
# 다른 모든 요청 처리
...
}
이 설정은 다음과 같은 역할을 합니다:
- Let's Encrypt의 도메인 소유권 확인 요청(
/.well-known/acme-challenge/
)을 win-acme 디렉토리로 전달합니다. -
try_files $uri =404
설정으로 SPA(Single Page Application) 리다이렉트와 같은 간섭을 방지합니다. - HTTP 요청을 HTTPS로 리다이렉트합니다.
인증서 갱신 후 NGINX를 자동으로 재시작하기 위한 배치 스크립트를 생성합니다:
-
C:\Tools\win-acme\Logs
디렉토리를 생성합니다. -
C:\Tools\win-acme\Scripts
디렉토리에restart-nginx.bat
파일을 생성합니다. - 내용은 다음과 같습니다:
@echo off
echo %DATE% %TIME% Certificate renewed, restarting nginx >> C:\Tools\win-acme\Logs\nginx-restart.log
powershell -Command "Restart-Service -n nginx" >> C:\Tools\win-acme\Logs\nginx-restart.log 2>&1
echo %DATE% %TIME% Restart completed >> C:\Tools\win-acme\Logs\nginx-restart.log
이 스크립트는 인증서가 갱신될 때마다 NGINX 서비스를 재시작하고 로그를 기록합니다.
PowerShell 또는 명령 프롬프트를 관리자 권한으로 실행한 후 win-acme 디렉토리로 이동, wacs.exe를 실행합니다:
cd C:\Tools\win-acme
wacs.exe
프로그램을 실행하면 다음과 같은 메뉴가 표시됩니다:
N: Create certificate (default settings)
M: Create certificate (full options)
R: Run renewals (0 currently due)
A: Manage renewals (0 total)
O: More options...
Q: Quit
Please choose from the menu:
M
을 입력하고 Enter를 누릅니다.
다음 질문에 답변합니다:
Please specify how the list of domain names that will be included in the
certificate should be determined. If you choose for one of the "all bindings"
options, the list will automatically be updated for future renewals to
reflect the bindings at that time.
1: Read bindings from IIS
2: Manual input
3: CSR created by another program
C: Abort
How shall we determine the domain(s) to include in the certificate?:
- 입력:
2
(Manual input - 수동 입력)
Host:
- 입력: 인증서를 발급받을 도메인 이름 (예:
www.example.com,test.example.com
) - 쉼표(',')를 구분자로 복수 도메인 입력 가능
Friendly name '[Manual] www.example.com'. <Enter> to accept or type desired name:
- 입력: Enter 키를 눌러 기본값 수락
By default your source identifiers are covered by a single certificate. But
if you want to avoid the 100 domain limit, want to prevent information
disclosure via the SAN list, and/or reduce the operational impact of a single
validation failure, you may choose to convert one source into multiple
certificates, using different strategies.
1: Separate certificate for each domain (e.g. *.example.com)
2: Separate certificate for each host (e.g. sub.example.com)
3: Separate certificate for each IIS site
4: Single certificate
C: Abort
Would you like to split this source into multiple certificates?:
- 입력:
4
Single certificate
The ACME server will need to verify that you are the owner of the domain
names that you are requesting the certificate for. This happens both during
initial setup *and* for every future renewal. There are two main methods of
doing so: answering specific http requests (http-01) or create specific dns
records (dns-01). For wildcard identifiers the latter is the only option.
Various additional plugins are available from
https://github.com/win-acme/win-acme/.
1: [http] Save verification files on (network) path
2: [http] Serve verification files from memory
3: [http] Upload verification files via FTP(S)
4: [http] Upload verification files via SSH-FTP
5: [http] Upload verification files via WebDav
6: [dns] Create verification records manually (auto-renew not possible)
7: [dns] Create verification records with acme-dns (https://github.com/joohoi/acme-dns)
8: [dns] Create verification records with your own script
9: [tls-alpn] Answer TLS verification request from win-acme
C: Abort
How would you like prove ownership for the domain(s)?:
- 입력:
1
([http] Save verification files on (network) path - 네트워크 경로에 확인 파일 저장)
Path:
- 입력: 웹 서버가 HTTP 확인 요청을 처리할 루트 경로 (예:
C:\Tools\win-acme
)
Copy default web.config before validation? (y/n*)
- 입력:
n
(아니오)
After ownership of the domain(s) has been proven, we will create a
Certificate Signing Request (CSR) to obtain the actual certificate. The CSR
determines properties of the certificate like which (type of) key to use. If
you are not sure what to pick here, RSA is the safe default.
1: Elliptic Curve key
2: RSA key
C: Abort
What kind of private key should be used for the certificate?:
- 입력:
2
(RSA key - RSA 키)
When we have the certificate, you can store in one or more ways to make it
accessible to your applications. The Windows Certificate Store is the default
location for IIS (unless you are managing a cluster of them).
1: IIS Central Certificate Store (.pfx per host)
2: PEM encoded files (Apache, nginx, etc.)
3: PFX archive
4: Windows Certificate Store (Local Computer)
5: No (additional) store steps
How would you like to store the certificate?:
- 입력:
2
(PEM encoded files - PEM 인코딩 파일, Apache, NGINX 등에 적합)
File path:
- 입력: 인증서 파일을 저장할 경로 (예:
C:\nginx\certs
)
Password to set for the private key .pem file.
1: None
2: Type/paste in console
3: Search in vault
Choose from the menu:
- 입력:
1
(None - 비밀번호 없음)
Would you like to store it in another way too?:
- 입력:
5
(No (additional) store steps - 추가 저장 없음)
With the certificate saved to the store(s) of your choice, you may choose one
or more steps to update your applications, e.g. to configure the new
thumbprint, or to update bindings.
1: Create or update bindings in IIS
2: Start external script or program
3: No (additional) installation steps
Which installation step should run first?:
- 입력:
2
(Start external script or program - 외부 스크립트 실행)
File:
- 입력: 인증서 갱신 후 실행될 스크립트 경로 (예:
C:\Tools\win-acme\Scripts\restart-nginx.bat
)
Parameters:
- 입력: Enter 키를 눌러 기본값 수락 (매개변수 없음)
Add another installation step?:
- 입력:
3
(No (additional) installation steps - 추가 설치 단계 없음)
Do you want to specify the user the task will run as? (y/n*) - yes
- 입력:
y
(예)
Enter the username (Domain\username):
- 입력: 작업을 실행할 사용자 계정 (최고 권한을 가진 관리자 계정을 입력하면 오류가 일어날 가능성을 최소화할 수 있습니다. 예:
Administrator
)
Enter the user's password:
- 입력: 해당 계정의 비밀번호
작업이 완료되면 인증서가 생성되고 지정된 경로에 저장됩니다. 이 인증서 파일은 다음과 같이 생성됩니다:
-
[도메인명]-chain.pem
: 인증서와 체인 인증서가 포함된 파일 -
[도메인명]-key.pem
: 개인 키 파일 -
[도메인명]-crt.pem
: 인증서만 포함된 파일 -
[도메인명]-chain-only.pem
: 체인 인증서만 포함된 파일
또한 인증서 갱신을 위한 작업 스케줄러 항목이 생성됩니다.
- 기본 설정: 매일 오전 9시에 인증서 유효 기간 확인, 필요시 갱신
- 작업 스케줄러(
taskschd.msc
)에서 편집 가능
인증서 발급이 완료되면 NGINX 구성 파일(nginx.conf)의 HTTPS 서버 블록에서 인증서 경로를 설정해야 합니다:
server {
listen 443 ssl;
server_name example.com www.example.com;
...
ssl_certificate C:/nginx/certs/www.example.com/www.example.com-chain.pem;
ssl_certificate_key C:/nginx/certs/www.example.com/www.example.com-key.pem;
...
# 기타 SSL 설정 (필요시 추가)
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_prefer_server_ciphers on;
# ... 기타 설정
}
설정 변경 후 NGINX를 재시작하면 HTTPS가 활성화됩니다.
win-acme는 작업 스케줄러에 갱신 작업을 등록해 인증서 만료 전에 자동으로 갱신을 시도하도록 설정합니다. 기본 설정은 다음과 같습니다:
- 시작 시간: 오전 09:00
- 무작위 지연: 4시간
- 시간 제한: 2시간
인증서를 수동으로 갱신하려면 다음 명령어를 사용합니다:
cd C:\Tools\win-acme
.\wacs.exe --renew
현재 만료되지 않은 인증서를 강제로 갱신하려면 --force
옵션을 사용합니다:
cd C:\Tools\win-acme
.\wacs.exe --renew --force
-
.\wacs.exe
: win-acme 프로그램 실행 -
.\wacs.exe --renew
: 만료 예정인 인증서 갱신 -
.\wacs.exe --renew --force
: 모든 인증서 강제 갱신 -
.\wacs.exe --list
: 관리 중인 인증서 목록 표시
-
--baseuri
: ACME 서버 URI 지정 (기본값: Let's Encrypt) -
--verbose
: 자세한 로그 출력 -
--test
: 테스트 서버 사용 (실제 인증서 발급하지 않음) -
--nocache
: 캐시를 사용하지 않고 새 인증서 요청
이 매뉴얼은 win-acme 버전 2.2.9.1701을 기준으로 작성되었습니다. 다른 버전에서는 일부 옵션이나 절차가 다를 수 있습니다.