티스토리 뷰

반응형

간단 SSL 적용 방법을 알아봅시다.

1. certbot 설치

2. python3-certbot-apache 설치

3. libapache2-mpm-itk 설치

4. 아파치 도메인 연결 설정

5. 사이트 파일 등록

6. 아파치 리로드

7. SSL 자동갱신

 

 

SSL 적용 전 준비

certbot 설치

# sudo apt install certbot

python3-certbot-apache 설치

# sudo apt install python3-certbot-apache

libapache2-mpm-itk 설치

# sudo apt install libapache2-mpm-itk

 

아파치 도메인 연결 설정

먼저 설정 디렉토리로 이동

# cd /etc/apache2/sites-available

다음은 설정 파일 생성

# vi 내도메인.conf

만약에 내 도메인이 www.domain.com이라면 아래와 같이 입력한다. 

 vi www.domain.com.conf 

그리고 내용은 아래와 같이 입력

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    
    DocumentRoot /home/username/www

    <Directory /home/username/www>
        Options FollowSymLinks MultiViews
        AllowOverride All
        require all granted

        php_value upload_max_filesize 100M
        php_value post_max_size 120M

        php_value session.cookie_httponly 1
        php_value session.use_strict_mode 1

        # php_value memory_limit 128M
        # php_value max_execution_time 30
        # php_value max_input_time 60
    </Directory>

    AssignUserID username username

    ErrorLog ${APACHE_LOG_DIR}/domain.com-error.log
    CustomLog ${APACHE_LOG_DIR}/domain.com-access.log combined

</VirtualHost>

 

아래의 URL에 들어가면 몇 가지 사항을 입력하면 자동으로 conf 파일을 만들어준다.

https://webmaster.cafe/tools/apache-conf-generator/

 

Apache2 환경설정 생성기 | 웹마스터카페

webmaster cafe

webmaster.cafe

 

사이트 파일 등록

# a2ensite www.domain.com.conf

 

아파치 리로드

# systemctl reload apache2

 

 

SSL 적용

# certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email admin@domain.com -d www.domain.com

모든 준비가 끝나고 위의 명령어를 자신에게 맞게 입력하면 "내도메인-le-ssl.conf"와 같은 파일이 생성된다.

이후 " http://내도메인 "으로 접속하면 " https://내도메인 "으로 리다이렉션된다.

 

 

SSL 자동갱신

자동갱신을 위해서는 crontab에 아래의 문구를 추가한다.

# crontab -e

( 내용 : 매월 1일마다 오전 5시에 갱신을 실행 )

 0 5    1 * *   root    certbot renew --quiet

추가 후 모습은 아래와 같다.

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
 0 5    1 * *   root    certbot renew --quiet
#

 

 

 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함