본문 바로가기

공부내용 정리/프로그래밍

[SSL] Lets'Encrypt 로 인증서 발급받기

https:// 가 아닌 주소를 사용하면 주의요함 경고 메시지가 보인다.

HTTPS 가 필요한 이유는

HTTP프로토콜을 사용할 경우 웹서버와 웹브라우저 사이에 주고받는 데이터가 암호화되지 않으므로 이 과정에서 누군가가 데이터를 훔쳐볼 수 도 있다. 이 말은 서비스의 보안이나 개인정보가 보호되지 않는다는 의미이기도 하다.

HTTP에 SSL(Secured Socket Layer) 기능을 더한 HTTPS프로토콜이 웹브라우저와 서비스 사이의 네트워크 구간에서 주고받는 데이터를 암호화하여 데이터가 노출되더라도 무슨내용인지 알 수 없도록 하는 역할을 한다.

서비스에 HTTPS 프로토콜을 제공하려면 SSL 인증서가 필요하므로 무료 SSL 인증서를 발급받아서 Nginx에 적용해보자.

Nginx는 높은 성능을 위해서 개발된 웹서버로, 설정이 간단하고 쉽게 사용할 수 있다.

유료인증서는 보안사고시 인증서에 따라 배상금을 인증 기관에서 지급해준다고 한다.  (대기업이나 금융 기관에서는 유료를 사용하는 이유)


sudo apt install certbot

sudo apt install python3-certbot-nginx

 

certbot은 SSL 인증서를 생성, 발급, 갱신, 관리하는데 사용한다.

python3-cerbot-nginx는 certbot을 Nginx 웹서버와 함께 사용하려면 필요하다.

설치 후 LetEncrypt의 인증서를 발급받으면 된다.


ubuntu@jumpto:~$ sudo certbot certonly --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mymailname@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: y
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): myservicename.co.kr
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for pybo.kr
Using default address 80 for authentication.
Waiting for verification...

 

위의 순서대로 입력시 인증서가 발급됨

/etc/letsencrypt/live/myservicename.co.kr/fullchain.pem

/etc/letsencrypt/live/ myservicename .co.kr/privkey.pem


myservicename .co.kr 외에 www. myservicename .co.kr 도 받고 싶어서 아래처럼 했다.

sudo certbot --nginx -d myservicename .co.kr -d http://www. myservicename .co.kr 

 

sudo vi /etc/nginx/site-availables/todo

server {
        listen 80;
        server_name myservicename.co.kr www.myservicename.co.kr;
        rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
        listen 443 ssl;
        server_name myservicename.co.kr www.myservicename.co.kr;

        ssl_certificate /etc/letsencrypt/live/myservicename.co.kr/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/myservicename.co.kr/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

        location / {
                proxy_pass http://localhost:8080;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
        }
}

 



sudo nginx -t
sudo systemctl restart nginx.service

 

이제 서비스로 접속해보면 주의요함이 사라지고 연결이 안전하다고 한다!

 

끝!