Certbot으로 인증서 발급 시 방화벽 오류 수정

Ubuntu에서 Certbot으로 https 인증서를 발급할 때 방화벽 오류가 발생합니다.

그래서 다른 방법을 찾아봤습니다.

해결 방법은 도메인을 연결할 때 도메인 서버에 TXT 레코드를 등록하는 것입니다.

내 로컬 서버는 DNS 서비스를 제공하지 않기 때문에 도메인을 발급한 호스팅 업체와 도메인에 연결할 때 A 레코드와 발급된 도메인을 등록하고 TXT 레코드를 별도로 등록하는 방법이 있습니다.

Certbot으로 DNS를 통해 수동으로 인증서를 발급하는 방법

보통 인증서가 발급되면 (참고로 아래 도메인은 제가 모르는 도메인입니다. 수정^^;) 정상이면 그대로 진행되지만 아래와 같이 방화벽 오류 메시지와 함께 발급이 중지됩니다.

root@ry:/home/ssi# certbot certonly --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: ry.com
2: www.ry.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Requesting a certificate for realtykr.shop and www.ry.com

Certbot failed to authenticate some domains (authenticator: nginx). The Certificate Authority reported these problems:
  Domain: ry.com
  Type:   connection
  Detail: 1**.2**.1**.2**: Fetching http://ry.com/.well-known/acme-challenge/4_LVG1354dsdgsdgdgdggdgdnuVb1Y: Timeout during connect (likely firewall problem)

  Domain: www.ry.com
  Type:   connection
  Detail: 1**.2**.1**.2**: Fetching http://www.ry.com/.well-known/acme-challenge/u2g0dgdgdgdgas23323tgsegb1nKM_EANy6fg0E: Timeout during connect (likely firewall problem)

Hint: The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. Ensure the listed domains point to this nginx server and that it is accessible from the internet.

Some challenges have failed.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

방화벽을 높이고 443번 포트와 80번 포트를 열고 방화벽을 꺼도 같은 현상이 계속 발생합니다. 며칠 고민하다가 우연히 DNS 연결 설정에서 인증서를 발급하는 방법을 찾았습니다.

아래와 같이 DNS 연결을 통해 수동으로 인증서를 받을 수 있습니다.

root@ry:/home/ssi# certbot certonly -d "*.ry.com" --manual --preferred-challenges dns
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for *.ry.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.ry.com.

with the following value:

CvqiPNMLrdXU88329846486328922AR7CnV-mI   : 값은 변조함. ^^;

위 명령어 실행 후 인증값이 나오면 누르지 마세요. , 먼저 도메인 관리 사이트로 이동하여 도메인 연결 시 A레코드를 등록하고 추가 TXT 레코드를 등록한 후 호스트에서 입력값 _acme-challenge에 생성값 CvqiPNMLrdXU88329846486328922 AR7 CnV-mI를 입력한다.

그런 다음 새 터미널을 열고 다음을 입력하여 DNS에 대한 연결이 설정되었는지 확인합니다.

#nslookup -q=TXT _acme-challenge.ry.com

검색에 성공하면 인증키 출력단자로 이동하여 다음을 입력합니다. 그리고 과정을 마칩니다.

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.ry.com.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/ry.shop/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/ry.shop/privkey.pem

두 개의 인증 키가 /etc/letsencrypt/live/ry.shop/ 위치에 저장됩니다.

이 인증 키는 /etc/nginx/sites-available/{domain}입니다. conf에 등록하면 됩니다.

다음 셸 창은 domain.conf의 예입니다. 사이트 설정에 맞게 조정할 수 있습니다.

## http://ry.com and http://www.ry.com redirect to https://www.ry.com
server {
listen 80;
listen (::):80;
server_name ry.com www.ry.com;

include /etc/nginx/snippets/letsencrypt.conf;

location / {
return 301 https://www.ry.com$request_uri;
}
}

 

## Serves https://www.ry.com
server {
server_name www.ry.com;
listen 443 ssl http2;
listen (::):443 ssl http2;

ssl_certificate /etc/letsencrypt/live/ry.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ry.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/ry.com/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;

root /var/www/ry.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}

## https://ry.com redirects to https://www.ry.com
server {
listen 443 ssl http2;
listen (::):443 ssl http2;
server_name ry.com;

ssl_certificate /etc/letsencrypt/live/ry.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ry.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/ry.com/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;

location / {
return 301 https://www.ry.com$request_uri;
}
}

이번 포스팅을 마치겠습니다. 감사해요