[테스트 서버 환경]
OS : Centos7
Apache : 2.4.7 v
Php : 7.2 v
Mysql : 5.5 v
우선 기본 환경 셋팅 후 netstat 명령어로 데몬들이 정상적으로 올라왔는지 확인한다.
# netstat -nltp
연결하려는 가상호스트 도메인들이 정상적으로 올라와있는지 확인한다.
# /usr/local/apache/bin/apachectl -S
패키지 설치의 경우 절대경로를 다 작성해 줄 필요 없이 apachectl -S 명령어로도 확인이 가능하다.
apache 모듈 중 mod_ssl 설치되어 있는지 확인
# /usr/local/apache/bin/apachectl -M
mod_ssl 모듈이 없다면 패키지 설치의 경우 아래 명령어로 설치한다.
# yum install mod_ssl -y
컴파일 설치의 경우 --enable-ssl 옵션을 넣어서 아파치 재컴파일을 해준다.
httpd.conf 설정파일에서 아래의 모듈이 load 되어 있는지 확인한다.
주석처리 되어있다면 주석 해제해준다.
# vi /usr/local/apache/conf/httpd.conf
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule socache_dbm_module modules/mod_socache_dbm.so
LoadModule ssl_module modules/mod_ssl.so
ssl.conf 설정파일을 사용할것이므로 해당 파일도 include 될 수 있도록 주석처리되어 있다면 해제한다.
Include conf/extra/httpd-ssl.conf
설치할 환경이 모두 준비되었으면 certbot을 설치한다.
# yum install -y certbot
아래 형식과 동일하게 작성 후 설치해주면 되는데,
certbot certonly -a webroot --agree-tos -m [메일주소] -w [DocumentRoot] -d [도메인1] -d[도메인2....] --rsa-key-size 4096
An unexpected error occurred: There were too many requests of a given type :: Error creating new cert :: too many certificates already issued for exact set of domains
letsencrypt의 경우 하루에 5번밖에 설치할 수 없기 때문에 옵션을 잘못 넣어 설치에 실패할 경우 위와 같은 에러 메시지가 뜨면서 설치가 되지 않는 난감한 일이 발생할 수 있으므로, --dry-run 옵션을 꼭 넣어 테스트 후 설치하는 방법을 추천한다.
certbot certonly -a webroot --agree-tos -m [메일주소] -w [DocumentRoot] -d [도메인1] -d[도메인2....] --rsa-key-size 4096 --dry-run
ex) # certbot certonly -a webroot --agree-tos -m wnwlsxxx@naver.com -w /home/test -d test.com --rsa-key-size 4096 --dry-run
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/test.com/cert.pem
/etc/letsencrypt/live/test.com/privkey.pem
/etc/letsencrypt/live/test.com/fullchain.pem
정상적으로 인증서를 받아오는데 성공하면 위와 같은 메시지가 뜨면서 인증서 설치 경로를 알려준다.
위의 파일 위치를 복사해서 ssl.conf 파일에 인증서 경로를 넣어주면 됨.
# vi /usr/local/apache/conf/extra/httpd-ssl.conf
Listen 443 --> 443으로 되어있는지 확인
<VirtualHost *:443>
DocumentRoot /home/test
ServerName test.com
ServerAlias test.com
ErrorLog "/usr/local/apache/logs/test.com_error_ssl.log"
TransferLog "/usr/local/apache/logs/test.com_access_ssl.log"
SSLCertificateFile "/etc/letsencrypt/live/test.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/test.com/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/test.com/fullchain.pem"
--> 3개 인증서 경로를 넣어주어야하는 인증서 옵션에 맞게 잘 확인 후 등록
재시작 전 문법 틀린부분 없는지 확인
# /usr/local/apache/bin/apachectl -t
Syntax OK
확인 후 이상 없으면 아파치 재시작
# /etc/init.d/apachectl restart
443 포트가 정상적으로 올라왔는지 확인하고, 가상호스트도 443포트로 잘 올라왔는지 확인한다.
# netstat -nltp
# /usr/local/apache/bin/apachectl -S
VirtualHost configuration:
*:443 test.com (/usr/local/apache/conf/extra/httpd-ssl.conf:122)
letsencrypt의 경우 3개월마다 인증서가 만료되므로, 갱신해주는 명령어를 crontab에 등록하여 사용하는것이 좋다.
# vi /etc/crontab
30 4 1 * * certbot renew
31 4 1 * * /etc/init.d/apachectl stop
32 4 1 * * /etc/init.d/apachectl start
--> 매월 1일 새벽 4시 30분 경 인증서 갱신 후 아파치를 재시작하도록 설정하였다.
'Linux > 일반' 카테고리의 다른 글
nodejs 16.x 설치 (0) | 2023.01.16 |
---|---|
로드밸런서 이해하기 ( #2. SSL 인증서 등록, 포트포워딩, log 확인 ) (0) | 2023.01.10 |
로드밸런서 이해하기 ( #1. 개념 및 이해 ) (0) | 2023.01.09 |
sftp 상위디렉토리 접근 제한 (0) | 2023.01.06 |
linux NFS 서버 설치 (0) | 2022.11.10 |