0) 설치 환경 ( OS: 우분투18.04, 웹서버 : 아파치2, 톰캣 9.0 )
1) 아파치 설정(도메인 주소 설정)
sudo nano /etc/apache2/sites-available/000-default.conf
2) letsencrypt 설치
$ sudo apt-get update
$ sudo apt-get install letsencrypt
3) 아파치 STOP(나는 이 순서를 생략해도 잘 동작됬다.)
$ sudo service apache2 stop
SSL 인증서를 받기 위한 명령어를 쳐야 하는데,
이 명령어가 실행될 때 80포트를 사용하기 때문에 80포트를 비워줘야 한다고 한다.
아파치가 기본적으로 80포트에 물려 있기 때문에 아파치를 꺼준다.
4) 현재 사용 포트 확인(나는 이 순서를 생략해도 잘 동작됬다.)
sudo netstat -tnlp|grep 80 : 80포트가 있는지 확인
sudo netstat -atlpvn : 모든 포트 확인
netstat -ntl
80포트가 꺼지면 나오지 않는다.
6) 인증서 발급과정
아래처럼 프로젝트 루트의 경로를 수동적으로 잡아서 발급을 해줬다.
letsencrypt certonly --webroot --webroot-path=웹루트 -d 도메인
예 : letsencrypt certonly --webroot --webroot-path=/var/lib/tomcat9/webapps -d dokky.site
certonly 옵션을 주는 이유는 certbot보고 인증서 발급만 하고 다른 아파치 설정은 건드리지 말라
는 뜻이다. certonly를 빼고 명령을 실행하면 예상치 못한 일이 생길 수 있으니 주의
--
debug : 명령어에 이렇게 debug추가해주면 에러 로그도 나온다.
이때 톰캣의 server.xml 에 <!--<Context docBase="MyPortFolio" path="/" reloadable="true" />--> 주석처리해야함
그리고 아래설정을 진행 해준다
- 이메일 입력
1
2
|
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): test@gmail.com
|
cs |
- 이용 약관 동의 (A:동의)
1
2
3
4
5
6
7
|
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a
|
cs |
- Let’s Encrypt의 뉴스레터 수신 여부 (Y:동의 N:거부) - (선택사항) 거부해도 상관없으니 원하는 대로
1
2
3
4
5
|
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
(Y)es/(N)o: n
|
cs |
7) 발급 완료 메시지
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/dokky.ga/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/dokky.ga/privkey.pem
Your cert will expire on 2020-02-22. 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
|
cs |
8) 인증서파일 발급 위치
완료되면 위와 같이 키가 발급된 위치가 나온다.
경로를 따라가면 인증서 파일 4개가 발급되어있다.
cert.pem : 인증서 파일.
chain.pem : 인증서 발급자 파일.
fullchain.pem : cert.pem과 chain.pem을 하나로 합쳐놓은 파일.
privkey.pem : 개인키 파일.
1
2
3
|
/etc/letsencrypt/live/dokky.ga# ls
README cert.pem chain.pem fullchain.pem privkey.pem
|
cs |
9) https 서비스를 위한 가상 호스트를 아파치에 설정
SSL 환경설정 파일 열기
sudo nano /etc/apache2/sites-available/default-ssl.conf
아래 부분들을 추가해준다.
2
3
4
5
6
7
|
ServerName dokky.ga ServerAdmin 이메일 ServerAlias dokky.ga #DocumentRoot /var/www/html DocumentRoot /var/lib/tomcat9/webapps/
JkMount /* tomcat1
SSLEngine on
SSLCertificateFile “/etc/letsencrypt/live/[도메인주소]/cert.pem”
SSLCertificateKeyFile “/etc/letsencrypt/live/[도메인주소]/privkey.pem”
SSLCertificateChainFile “/etc/letsencrypt/live/[도메인주소]r/chain.pem”
|
cs |
이처럼 아파치 설정에 인증서의 위치를 잡아주면 아파치 서버로 요청이 들어올시 SSL이 적용되어 인증서가 확인이 된다.
현재 ROOT 라는 이름으로 프로젝트 배포하기 때문에 아래와 같이 경로 변경했음 DocumentRoot /var/lib/tomcat9/webapps/ROOT/
10) Apache 웹서버의 SSL 가상호스트 사이트 설정 활성화
#a2ensite default-ssl.conf (비활성: a2dissite default-ssl.conf)
1
2
3
|
Enabling site default-ssl.
To activate the new configuration, you need to run:
systemctl reload apache2
|
cs |
11) Apache 웹서버의 SSL 모듈 활성화
sudo a2enmod ssl( 비활성 : sudo a2dismod ssl )
12) 방화벽 설정
- 호스팅 사이트 방화벽 확인
1
2
3
4
5
6
7
8
9
10
|
# 방화벽 상태보기
$ sudo ufw status verbose
# 방화벽 열기
$ sudo ufw allow http
$ sudo ufw allow https
$ sudo ufw allow ssh
# 방화벽 활성화
$ sudo ufw enable
|
cs |
혹시 위처럼 안열려있는 포트가 있다면 열어주자
- sudo ufw allow 포트번호/tcp
1
2
3
4
|
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="8443"
maxThreads="150" scheme="https" secure="true" SSLEnabled="true"
keystoreFile="/etc/letsencrypt/live/dokky.ga/cert_and_key.jks"
keystorePass="password" clientAuth="false" sslProtocol="TLS" />
|
cs |
sudo nano /etc/apache2/sites-available/000-default.conf : 아파치 설정파일 수정
HTTP 80포트로 들어오는 요청을 https로 리다이렉트 시켜준다
1
2
3
4
5
6
7
|
<VirtualHost *:80>
RedirectPermanent / https://dokky.ga/
</VirtualHost>
|
cs |
15) 아파치, 톰캣 재시작
systemctl restart apache2 && systemctl restart tomcat9
sudo service apache2 restart
sudo service tomcat9 restart
참고 블로그
https://all-record.tistory.com/190
https://www.comodossl.co.kr/certificate/ssl-installation-guides/Tomcat-csr-crt.aspx
https://hiseon.me/server/apache-ssl-setting/
https://hiseon.me/server/letsencrypt-ssl-certificate/
https://devlog.jwgo.kr/2019/04/16/get-ssl-cert-from-letsencrypt/
https://devlog.jwgo.kr/2019/04/16/get-ssl-cert-from-letsencrypt/
https://jimnong.tistory.com/742
https://onecellboy.tistory.com/341
'Basic > 네트워크' 카테고리의 다른 글
구글로그인 (0) | 2019.12.08 |
---|---|
OAuth 2.0 (0) | 2019.12.08 |
TCP/IP 의 개념 (0) | 2019.11.19 |
SSL의 구체적인 동작방법 (0) | 2019.09.27 |
SSL의 핵심 동작방법 (0) | 2019.09.27 |