본문 바로가기

리눅스

Let's Encrypt(certbot)에서 SSL 인증서를 발급받는 방법

728x90

Let's Encrypt(certbot)에서 SSL 인증서를 발급받는 방법

1. Standalone 모드로 인증서 발급하기

이 방법은 웹 서버가 없는 경우에 사용됩니다. Certbot은 자체적으로 웹 서버를 실행하고 ACME 도메인 검증을 처리합니다.

"독립 실행형" 웹 서버를 사용하여 인증서를 가져옵니다.

포트 80을 사용할 수 있어야 합니다. 이 기능은 웹 서버가 없거나 로컬 웹 서버와의 직접 통합이 지원되지 않거나 원하지 않을 때 유용합니다.

  • 80(HTTP) 또는 443(HTTPS) 포트 오픈되어 있어야함(방화벽 정책 오픈)
  • 80(HTTP) 또는 443(HTTPS)을 사용(기존 웹 서버 중단)
  • 도메인이 자신의 서버에 연결되어 있어야함(A 레코드 설정)
certbot certonly --standalone -d [도메인명1] -d [도메인명2]
certbot certonly --standalone -d example.com -d www.example.com

이 명령어는 example.com과 www.example.com 도메인에 대한 인증서를 발급합니다. Certbot은 임시 웹 서버를 실행하여 Let's Encrypt와 통신하며, 인증을 완료한 후에는 임시 서버를 종료합니다.

2. webroot 모드로 인증서 발급하기

웹 서버의 루트 디렉토리에 정적 파일을 생성하여 ACME 도메인 검증을 처리합니다.

이미 실행 중인 웹 서버의 웹 루트 디렉터리에 기록하여 인증서를 가져옵니다.

  • 웹 서버 중단없이 발급
  • 웹서버에 사전 세팅이 필요
  • 자동 갱신 가능
  • letsencrypt 폴더가 인증에 사용됨(/var/www/letsencrypt/.well-known/acme-challenge)
certbot certonly --webroot -w [접근 가능 경로] -d [도메인명1]
certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
certbot certonly --webroot --agree-tos --no-eff-email --email [email protected] --webroot-path=/var/www/letsencrypt -d www.sangchul.kr

여기서 -w 옵션은 웹 서버의 루트 디렉토리를 지정하며, -d 옵션으로 발급할 도메인을 지정합니다.

3. manual 모드로 인증서 발급하기

이 모드는 수동으로 DNS 레코드나 파일을 생성하여 도메인 소유권을 검증하는 방법입니다.

수동으로 지침에 따라 인증서를 가져와 도메인 검증을 직접 수행합니다. 이렇게 생성된 인증서는 자동 새로 만들기를 지원하지 않습니다.

도메인 유효성 검사 단계를 자동화하는 인증 후크 스크립트를 제공하여 자동 새로 만들기를 사용하도록 설정할 수 있습니다.

  • TXT 레코드 설정
certbot certonly --manual --preferred-challenges dns -d [도메인명1]
certbot certonly --manual -d example.com -d www.example.com
certbot certonly --manual --preferred-challenges dns --verbose --debug-challenge --staging -d www.sangchul.kr

명령어 실행 후 Certbot은 확인 작업을 위한 인증 정보를 제공하며, 사용자는 해당 정보를 따라 수동으로 도메인 소유권을 검증합니다.

728x90

4. apache 모드로 인증서 발급하기

Apache 웹 서버를 사용하는 경우, Certbot이 Apache 설정을 자동으로 구성하여 인증서를 발급받을 수 있습니다.

certbot --apache -d example.com -d www.example.com

Apache 모드에서는 Certbot이 Apache 설정 파일을 자동으로 수정하고 인증서를 발급받습니다.

5. nginx 모드로 인증서 발급하기

Nginx 웹 서버를 사용하는 경우에도 Certbot을 이용하여 nginx 설정을 자동으로 구성하여 인증서를 발급받을 수 있습니다.

certbot --nginx -d example.com -d www.example.com

nginx 모드에서도 Certbot은 nginx 설정 파일을 자동으로 수정하고 인증서를 발급받습니다.

 

위의 방법들을 사용하여 Let's Encrypt에서 SSL 인증서를 발급받을 수 있습니다. 각 방법은 환경에 따라 선택하시면 됩니다. Certbot과 Let's Encrypt의 공식 문서에서 더 자세한 정보를 확인하실 수 있습니다.

certbot 사용 방법

docker run -it --rm certbot/certbot --help
certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...
$ certbot --help

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate. The most common SUBCOMMANDS and flags are:

obtain, install, and renew certificates:
    (default) run   Obtain & install a certificate in your current webserver
    certonly        Obtain or renew a certificate, but do not install it
    renew           Renew all previously obtained certificates that are near
expiry
    enhance         Add security enhancements to your existing configuration
   -d DOMAINS       Comma-separated list of domains to obtain a certificate for

  (the certbot apache plugin is not installed)
  --standalone      Run a standalone webserver for authentication
  (the certbot nginx plugin is not installed)
  --webroot         Place files in a server's webroot folder for authentication
  --manual          Obtain certificates interactively, or using shell script
hooks

   -n               Run non-interactively
  --test-cert       Obtain a test certificate from a staging server
  --dry-run         Test "renew" or "certonly" without saving any certificates
to disk

manage certificates:
    certificates    Display information about certificates you have from Certbot
    revoke          Revoke a certificate (supply --cert-name or --cert-path)
    delete          Delete a certificate (supply --cert-name)

manage your account:
    register        Create an ACME account
    unregister      Deactivate an ACME account
    update_account  Update an ACME account
  --agree-tos       Agree to the ACME server's Subscriber Agreement
   -m EMAIL         Email address for important account notifications

More detailed help:

  -h, --help [TOPIC]    print this message, or detailed help on a topic;
                        the available TOPICS are:

   all, automation, commands, paths, security, testing, or any of the
   subcommands or plugins (certonly, renew, install, register, nginx,
   apache, standalone, webroot, etc.)
  -h all                print a detailed help page including all topics
  --version             print the version number
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 

728x90