ssl 인증서 설치를 통해 https 보안 연결을 사용할 수 있도록 해보겠습니다.
ssl 인증서는 Let's Encrypt에서 제공하는 무료 인증서를 이용합니다.
443 포트 개방하기
https 연결을 위해 가장 먼저 443 포트의 개방이 필요합니다.
443 포트 개방방법
링크로 대체합니다.
SSL 인증서 설치방법
certbot 설치하기
ssl 인증서 설치를 위해 python3-certbot-nginx를 install합니다.
~$ sudo apt install python3-certbot-nginx -y
ssl 인증서 발급방법
명령어는 "sudo certbot --nginx -d {your.domain.com}"입니다.
forum.seolpyo.com에 ssl 인증서를 설치한다면 다음과 같이 명령어를 입력하게 됩니다.
~$ sudo certbot --nginx -d forum.seolpyo.com
인증서 설치 진행시 이메일 주소를 요구하는데, ssl 인증서 기간 만료 알림, ssl 인증서 기간 만료 안내 이메일 등을 받을 수 있기 때문에 정확한 이메일을 등록하는 것이 좋습니다.
인증서 설치시 나오는 문구 번역
ssl 인증서 설치과정에서 몇 가지 안내문과 정보 입력을 요구하는데, 그 내용은 다음과 같습니다.(기계번역)
기계번역 | 원문 |
다음에서 서비스 약관을 읽어보세요. https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. 귀하는 다음 사항에 동의해야 합니다. ACME 서버에 등록하려면 동의하시나요? | Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in order to register with the ACME server. Do you agree? |
첫 번째 인증서가 성공적으로 발급되면 기꺼이 하시겠습니까? 전자프론티어재단(Electronic Frontier Foundation)과 귀하의 이메일 주소를 공유하세요. Let's Encrypt 프로젝트의 파트너이자 비영리 단체입니다. Certbot을 개발하나요? 웹 암호화 작업에 관해 이메일을 보내드리고자 합니다. EFF 뉴스, 캠페인 및 디지털 자유를 지원하는 방법. | Would you be willing, once your first certificate is successfully issued, 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. |
계정이 등록되었습니다. 인증서를 성공적으로 받았습니다. 인증서 배포 중 | Account registered. Successfully received certificate. Deploying certificate |
전체 과정
(django) ubuntu:~$ sudo certbot --nginx -d forum.seolpyo.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): aaa@aaa.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in
order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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
Account registered.
Requesting a certificate for forum.seolpyo.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/forum.seolpyo.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/forum.seolpyo.com/privkey.pem
This certificate expires on 2024-10-29.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for forum.seolpyo.com to /etc/nginx/sites-enabled/mysite
Congratulations! You have successfully enabled HTTPS on https://forum.seolpyo.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(django) ubuntu:~$
에러가 발생한다면?
다음과 같은 메세지가 노출되며 인증서 설치를 실패하는 경우가 있을 수 있습니다.
다음은 인증서를 설치하는 서버에 해당 도메인이 연결되지 않을 때 발생하는 에러입니다.
이 경우 서버에 도메인이 연결된 이후에 다시 시도하면 정상적으로 인증서 설치가 완료됩니ㅏㄷ.
Certbot failed to authenticate some domains (authenticator: nginx). The Certificate Authority reported these problems:
Domain: forum.seolpyo.com
Type: connection
Detail: **.**.***.**: Fetching http://forum.seolpyo.com/.well-known/acme-challenge/*************: Timeout during connect (likely firewall problem)
Hint: The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. Ensure the listed domains point to this nginx server and that it is accessible from the internet.
Some challenges have failed.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.
인증서 설치 완료
nginx 설정파일을 확인해보면 다음과 같이 수정되어있는 것을 확인할 수 있습니다.
# /etc/nginx/sites-available/mysite
server {
charset utf-8;
server_name forum.seolpyo.com;
# server_name {url domain 주소};
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
alias /home/ubuntu/django/mysite/static;
}
location /media {
alias /home/ubuntu/django/mysite/media;
}
location / {
include proxy_params;
proxy_pass http://unix:/tmp/mysite.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/forum.seolpyo.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/forum.seolpyo.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = forum.seolpyo.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name forum.seolpyo.com;
return 404; # managed by Certbot
}
https 주소로 접속해보기
이제부터 https 주소로 접속이 가능해집니다. cerbot이 자동으로 https 리다이렉트를 설정해주었기 때문에 http 주소로 접속하면 https 주소로 리다이렉트됩니다.
이 글의 댓글 기능은 일부러 막아놓았습니다. 궁금한 내용이 있다면 게시판을 이용해주세요!