Ubuntu 20.04 Apache + Let’sEncrypt SSL 인증서 적용하기

1) 사전 준비 -관리자 권한(su)일 것.-아피치는 설치되어 있을 것. 2) cerbot 설치 $ sudo apt update$ sudo apt install certbot 3)dh 키교환 생성(2048) $ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048시간이 오래 걸린다. 4)Let’s Encrypt SSL 인증서 받기 $ sudo mkdir -p /var/lib/letsencrypt/.well-known$ sudo chgrp www-data /var/lib/letsencrypt$ sudo chmod g+s /var/lib/letsencrypt 5)복제 방지를 위한 설정파일 작성 […]

apache ssl

1) 사전 준비

-관리자 권한(su)일 것.
-아피치는 설치되어 있을 것.

2) cerbot 설치

$ sudo apt update
$ sudo apt install certbot

3)dh 키교환 생성(2048)

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
시간이 오래 걸린다.

4)Let’s Encrypt SSL 인증서 받기

$ sudo mkdir -p /var/lib/letsencrypt/.well-known
$ sudo chgrp www-data /var/lib/letsencrypt
$ sudo chmod g+s /var/lib/letsencrypt

5)복제 방지를 위한 설정파일 작성

가. 첫번째 파일
$ nano /etc/apache2/conf-available/letsencrypt.conf
아래의 내용으로 작성

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
    AllowOverride None
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>

나. 두번째 파일
$ nano /etc/apache2/conf-available/ssl-params.conf
아래의 내용으로 작성

SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off


SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"


SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem" 


Header always set Strict-Transport-Security "max-age=63072000"

6)아파치 모듈 추가 및 실행

$ sudo a2enmod ssl
$ sudo a2enmod headers
$ sudo a2enconf letsencrypt
$ sudo a2enconf ssl-params
$ sudo a2enmod http2
$ sudo systemctl reload apache2

7) webroot에 ssl인증서 받기

예)이메일 주소 : yourid@youremail.com
예)도메인 주소 : your_domain_name.com
$ sudo certbot certonly –agree-tos –email yourid@youremail.com –webroot -w /var/lib/letsencrypt/ -d your_domain_name.com -d www.your_domain_name.com

아래와 같은 인증서 내용이 출력된다.
IMPORTANT NOTES:

  • Congratulations! Your certificate and chain have been saved at:
    /etc/letsencrypt/live/your_domain_name.com/fullchain.pem
    Your key file has been saved at:
    /etc/letsencrypt/live/your_domain_name.com/privkey.pem
    Your cert will expire on 2020-10-06. To obtain a new or tweaked
    version of this certificate in the future, simply run certbot
    again. To non-interactively renew all of your certificates, run
    “certbot renew”
  • Your account credentials have been saved in your Certbot
    configuration directory at /etc/letsencrypt. You should make a
    secure backup of this folder now. This configuration directory will
    also contain certificates and private keys obtained by Certbot so
    making regular backups of this folder is ideal.
  • If you like Certbot, please consider supporting our work by: Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
    Donating to EFF: https://eff.org/donate-le

8) 가상호스트 환경설정파일 작성 또는 수정

예)도메인 이름이 your_domain_name.com이라면
$ nano /etc/apache2/sites-available/your_domain_name.com.conf

<VirtualHost *:80> 
  ServerName your_domain_name.com
  Redirect permanent / https://your_domain_name.com/
</VirtualHost>


<VirtualHost *:443>
  ServerName your_domain_name.com
  Protocols h2 http/1.1


  <If "%{HTTP_HOST} == 'www.your_domain_name.com'">
    Redirect permanent / https://your_domain_name.com/
  </If>


  DocumentRoot /var/www/your_domain_name.com/public_html
  ErrorLog ${APACHE_LOG_DIR}/your_domain_name.com-error.log
  CustomLog ${APACHE_LOG_DIR}/your_domain_name.com-access.log combined


  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/your_domain_name.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/your_domain_name.com/privkey.pem


  # Other Apache Configuration
  # 홈페이지 root디렉토리가 test 라면......
  # 상황에 맞게 수정한다.
    Alias /test "/var/www/html/test/"
 
     <Directory /var/www/html/test/>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        SetEnv HOME /var/www/html/test
        SetEnv HTTP_HOME /var/www/html/test
     </Directory>
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

9) 아파치 재시작

$ sudo systemctl reload apache2

10)SSL 인증서 등급 테스트

https://www.ssllabs.com/ssltest/ 접속해서 홈페이지 주소를 입력하여 확인한다.
녹색바탕에 A+글씨가 보이면 잘 만들어 진 것이다.

Screenshot 2022 06 17 at 21.02.14

11)인증서 3개월마다 자동 업데이트 설정.

인증서 만료일 30일전에 하루에 2번 실행되게 cronjob 설정한다.
$ sudo nano /etc/cron.d/certbot 파일을 생성한다.

아래의 내용을 추가한다.

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload apache2"

$ sudo certbot renew –dry-run
명령을 실행해서 에러가 없으면 업데이트 작업이 추가된 것이다.

Views: 6

댓글 달기

위로 스크롤
Share via
Copy link
Powered by Social Snap