
docker run --rm \
-v ~/nginx-https/certbt/conf:/etc/letsencrypt \
-v ~/nginx-https/certbot/www:/var/www/certbot \
certbot/certbot renew --dry-run
Certbot이 자동 갱신을 정상적으로 작동하는지 테스트 하는 과정에서 위의 명령어를 입력하면
unauthorized 오류가 발생하며 실패하였다.
Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
Domain: showping.duckdns.org
Type: unauthorized
Detail: IP 주소: Invalid response from https://showping.duckdns.org/.well-known/acme-challenge/z7KXrkbHjbbg9VDQkqpHk4yBuXGVIwe4LJzEpwHf-o8: 404
Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.
Failed to renew certificate showping.duckdns.org with error: Some challenges have failed.
All simulated renewals failed. The following certificates could not be renewed:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/etc/letsencrypt/live/showping.duckdns.org/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
원인은 Nginx 설정 파일인 nginx.conf에 있었다.
Nginx가 HTTPS 요청을 처리할 수 있도록 아래와 같이 설정을 수정하였는데 /.well-known/acme-challenge/ 부분을 누락시킨 것이다.
Let's Encrypt 서버가 http://your-domain.com/.well-known/acme-challenge/토큰값을 요청하면 Nginx가 /var/www/certbot(즉, ./certbot/www)에서 파일을 제공해야 하는데 해당 부분이 누락되어 Nginx가 /.well-known/acme-challenge/ 경로를 제대로 서빙하지 못하여 문제가 발생한 것이다.
events {}
http {
server {
listen 80;
server_name your-domain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
해결 방법은 단순하다. 누락된 부분을 추가해주면 된다. nginx.conf 파일을 다음과 같이 수정하였다.
events {}
http {
server {
listen 80;
server_name your-domain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
다시 테스트 명령어를 실행해보면 이번에는 성공적으로 테스트가 완료되었다.