AI 요약
가비아에서 받은 인증서 파일을 윈도우 환경의 nginx에 맞게 cert.pem, chain.pem, privkey.pem으로 정리하고 fullchain.pem을 만들어 교체하는 과정을 정리한 글입니다. 백업을 먼저 하고 nginx 설정 검사를 한 뒤(권한 문제로 reload 대신) 재시작해 브라우저와 스크립트로 새 인증서가 반영되었는지 확인한 것이 핵심입니다.
가비아 ssl 인증서 갱신 자체는 어렵지 않다.
새로 받은 인증서 파일을 nginx가 사용하는 형식에 맞춰 배치하고 다시 읽게 만들면 된다.
이번 작업은 리눅스 서버가 아니라 윈도우 환경의 nginx였고 기존 서버 구조도 같이 확인해야 해서 단순한 파일 교체보다 조금 더 꼼꼼하게 진행했다.
보통 아래와 같은 파일을 받는다.
도메인_cert.crt
도메인_chain_cert.crt
도메인_root_cert.crt
도메인.key
각 파일의 역할은 다음과 같다.
| 파일 | 역할 |
|---|---|
| *_cert.crt | 도메인 인증서 |
| *_chain_cert.crt | 중간 인증서 |
| *_root_cert.crt | 루트 인증서 |
| *.key | 개인키 |
가비아에서 받은 파일을 다음처럼 맞췄다.
도메인_cert.crt -> cert.pem
도메인_chain_cert.crt -> chain.pem
도메인.key -> privkey.pem
그리고 cert.pem과 chain.pem을 합쳐 fullchain.pem을 만들었다.
01Get-Content cert.pem, chain.pem | Set-Content fullchain.pem -Encoding ascii루트 인증서 파일은 따로 보관만 했다.
현재 서버에서는 cert.pem + chain.pem 구성만으로 정상 동작했다.
운영 서버에서 인증서를 바로 덮어쓰면 롤백이 어려워진다.
기존 인증서와 Nginx 설정 파일을 먼저 백업했다.
01$stamp = Get-Date -Format 'yyyyMMdd_HHmmss'02$backup = "C:\backup\ssl-renew-$stamp"03 04New-Item -ItemType Directory -Force -Path $backup | Out-Null05Copy-Item C:\path\to\ssl\current\*.pem $backup\06Copy-Item C:\nginx\conf\nginx.conf $backup\새로 받은 파일을 nginx가 바라보는 위치에 복사했다.
01Copy-Item "도메인_cert.crt" "cert.pem" -Force02Copy-Item "도메인_chain_cert.crt" "chain.pem" -Force03Copy-Item "도메인.key" "privkey.pem" -Forcefullchain.pem을 다시 생성했다.
01Get-Content cert.pem, chain.pem | Set-Content fullchain.pem -Encoding ascii파일을 교체한 뒤 바로 재시작하지 않고 먼저 설정 검사를 했다.
01cd C:\nginx02.\nginx.exe -t정상이라면 아래처럼 나온다.
01nginx: the configuration file C:\nginx/conf/nginx.conf syntax is ok02nginx: configuration file C:\nginx/conf/nginx.conf test is successfulreload만 하면 되는 줄 알고 했더니 아래와 같은 오류가 발생했다.
01OpenEvent("Global\ngx_reload_xxxxx") failed (5: Access is denied)인증서 파일은 새 파일로 교체됐지만, 실행 중인 Nginx 프로세스가 아직 이전 인증서를 들고 있을 수 있다.
nginx를 재시작하고 실제 도메인에서 새 인증서가 내려오는지 확인했다.
서버에 복사된 인증서 파일 자체는 PowerShell로 확인할 수 있다.
01$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("cert.pem")02 03$cert.Subject04$cert.Issuer05$cert.NotBefore06$cert.NotAfter07($cert.NotAfter - $cert.NotBefore).Days실제 적용 확인은 브라우저 자물쇠 정보나 상태 확인 스크립트로 확인했다.
01SSL Subject : CN=도메인02SSL Issuer : GlobalSign GCC R6 AlphaSSL CA 202503SSL Expires : 2027-01-09정상 반영됐다.