UBUNTU 웹서버

Lets Encrypt 설정


Lets Encrypt 설정


  2021-09-15  1124 View 공개

IMPORTANT NOTES:

 - Congratulations! Your certificate and chain have been saved at:

   /etc/letsencrypt/live/skiresort.or.kr/fullchain.pem

   Your key file has been saved at:

   /etc/letsencrypt/live/skiresort.or.kr/privkey.pem

   Your cert will expire on 2021-12-14. 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'

 - 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




 

발급된 인증서 파일 확인 및 웹서버 설정 변경

 

발급된 Let's Encrypt의 SSL 인증서 파일은 아래와 같은 경로에 저장된다. 실제 파일은 archive 디렉토리 아래의 도메인주소 경로아래에 있으며 앞의 화면에서 보듯 live 디렉토리아래로 심볼릭 링크가 걸려 있다.

 

발급된 let
발급된 let's encrypt ssl 인증서가 저장된 경로

아마도 certbot renew 명령으로 갱신할 경우 archive 디렉토리의 파일들이 업데이트 되는 것 같다. (이건 3개월 뒤에 확인 가능함)

 

이렇게 SSL 인증서 파일들이 생성되면 웹서버에 해당 인증서 파일을 알려줘야 한다. 인증서 설정은 아래와 같이 웹서버 설정의 ssl 관련 conf 파일에 포함되어 있다. (앞의 000은 버전이나 상황에 따라 없을 수도 있다.)

Apache 웹서버의 ssl 인증서 설정 파일 (default-ssl.conf)
Apache 웹서버의 ssl 인증서 설정 파일 (default-ssl.conf)

vi 또는 nano 명령으로 000-default-ssl.conf 파일을 열고  몇개의 설정을 수정해준다.

apache 웹서버의 ssl 활성화 설정

만약 아파치 웹서버에 https를 지원하도록 설정하였다면 SSLEngine 옵션이 on이 되어 있어야 한다. 만약 이 옵션이 off 이면 아파치에 SSL 모듈이 설치되지 않았거나 로딩되지 않은 상태다. 다음의 명령을 통해 OpenSSL을 설치하고 아파치의 SSL 모듈을 구동해줘야 한다.

 

o OpenSSL 설치

  - sudo apt-get install openssl

 

o Apache2 SSL 모듈 로드

  - sudo a2enmod ssl

 

여기까지 작업한 뒤 위 화면처럼 SSL 설정을 변경해준다.

 

설정을 변경한 뒤 아래 명령을 다시한번 실행하여 기본웹사이트의 SSL(https) 설정을 적용하고 활성화한다.

apache 웹서버의 ssl 설정 적용하기

그리고 다음 명령으로 웹서버를 재기동한다.

 

o sudo service apache2 restart

 

http 접속을 https로 리다이렉션 하기

 

하지만 이용자가 http로 접속하면 ssl을 통한 암호화 통신은 적용되지 않는다. 따라서 http(tcp/80)으로 접속할 경우 https(tcp/443)으로 리다이렉션해줘야 한다. 여러 방법이 있지만 가장 확실하고 빠른 방법은 아파치2에서 무조건 http를 https로 리다이렉션 하도록 하는 방법이다.

 

아래와 같이 아파치의 DocumentRoot 디렉토리에 .htaccess 파일을 생성하고 아래 내용을 추가하는 것이다. 

apache web server, http를 https로 리다이렉션 설정하기
Apache 웹서버에서 http를 https로 리다이렉션 설정하기

이 방법은 아파치2의 mod_rewrite 모듈을 이용하는 것이기 때문에 아파치에 mod_rewrite 모듈이 설치되고 로드되어 있지 않다면 동작하지 않는다.

 

만약 Apache2에 mod_rewrite 모듈이 설치되어 있다면 다음의 명령을 수행한다.

 

a2enmod rewrite

 

이렇게 설정하면 웹브라우저에서 http로 접속을해도 https로 자동으로 전환된다.

 

브라우저에서 확인하기

 

적용한 웹사이트에 http로 접속하면 아래와 같이 자동으로 https로 전환되어 URL 앞에 자물쇠가 보인다.

그리고 자물쇠를 클릭해 인증서 정보를 확인하면 Le's Encrypt 인증서임을 확인할 수 있다.




8. 아파치에 ssl 키 등록하기

 - cd /etc/apache2/sites-available (디렉토리로 이동)

 - sudo cp default-ssl.conf kkensu.com-ssl.conf  (복사하기)

 - sudo vi kkensu.com-ssl.conf

 - 아래 내용 입력하여 파일 수정하기

<IfModule mod_ssl.c>
    <VirtualHost *:443> <!-- https 연결이 되지 않는다면 * 부분에 아이피를 넣어준다. x.x.x.x:443 -->
        ServerAdmin kkensu@gmail.com
        ServerName kkensu.com
        ServerAlias kkensu.com

        DocumentRoot /var/www/html
        
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        
        SSLEngine on
        
        SSLCertificateFile  /etc/letsencrypt/live/kkensu.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/kkensu.com/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/kkensu.com/chain.pem
        
        <FilesMatch '\.(cgi|shtml|phtml|php)$'>
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>
        
        </VirtualHost>
</IfModule>

 

9. kkensu.com 도메인 enable 설정하기

sudo a2enmod ssl <!-- ssl을 사용하겠다고 명시해주는 것 -->

sudo a2ensite kkensu.com-ssl.conf

 

 

10. 아파치 재기동

sudo service apache2 restart

 


 

11. http로 접속하면 https로 이동하도록 Redirect 걸기

 

<VirtualHost *:80>
     ServerName kkensu.com
     DocumentRoot /var/www/test
     Redirect permanent / https://kkensu.com/
     <Directory /var/www/html/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
     </Directory>
 </VirtualHost>

 

12. 끝!


Tags  #Lets_Encrypt  



🚩 UBUNTU 웹서버 글 모음 (총 14 건)

[APACHE] 아파치 로그에 이미지 제외하기

Last Updated : 2022-05-20
#Apache

[UBUNTU] APACHE2 설치

Last Updated : 2021-11-01
#Apache

[APACHE] 아파치 로그 로테이션 (rotetalogs)

Last Updated : 2021-10-15
#Apache

[APACHE] 아파치 로그파일 형식 지정

Last Updated : 2021-10-15
#Apache

Lets Encrypt 설정

Last Updated : 2021-09-15
#Lets_Encrypt

Alteon L4 초기 설정/로드밸런싱 설정

Last Updated : 2021-09-11