#11 : SSL
http 프로토콜에 보안기능(SSL)을 더한 것이 https이다.
01. HTTPS가 필요한 이유
- http는 클라이언트와 서버가 주고 받는 데이터가 암호화 되지 않는다.클라이언트와 서버 간의 네트워크 경로는 굉장히 복잡한데, 이 과정에서 해커가 사용자의 데이터를 훔쳐보는 일은 어렵지 않다.
- https는 http에 SSL(Secured Socket Layer) 기능을 더한 프로토콜이다.
- 우리가 만들 서비스에 https를 사용하기 위해서는 SSL 인증서가 필요하다. 인증서를 발급받아 Nginx에 적용하면 https프로토콜을 사용할 수 있다.
02. SSL 인증서 발급
- 인증기관에서 인증하는 인증서 필요 (대표적으로 Comodo, Thawte, GeoTrust, Digicert 등이 있고 유료이다.)
- 무료로 인증서를 발급해주는 Let's Encrypt를 사용하자.
03. Let's Encrypt 인증서 설치하기
- 서버 접속 후 cert 봇 설치
ubuntu@jumpto:~$ sudo apt install certbot
ubuntu@jumpto:~$ sudo apt install python3-certbot-nginx
- 인증서 발급
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): pahkey@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): pybo.kr
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for pybo.kr
Using default address 80 for authentication.
Waiting for verification...
(... 생략 ...)
순서대로 이메일, a, y, 도메인명 입력
(ip 주소로는 인증서 발급 불가능)
- 다음 위치에 인증서가 생성된다
/etc/letsencrypt/live/도메인명/fullchain.pem
/etc/letsencrypt/live/도메인명/privkey.pem
04. Nginx 설정
- SSL 인증서 Nginx 설정 sites-available/sbb 수정
server {
listen 80;
server_name pybo.kr;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443 ssl;
server_name pybo.kr;
ssl_certificate /etc/letsencrypt/live/pybo.kr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/pybo.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;
}
}
http인 80번 포트를 https 443번 포트로 리다이렉트하도록 설정,
- Nginx 재시작
ubuntu@jumpto:~$ sudo systemctl restart nginx.service
05. SSL 방화벽 설정
Nginx에 SSL을 적용하면 443포트 방화벽 설정이 필요하다.
서버 접속 설정 포스팅을 참고하여 방화벽 설정을 해보자.
06. HTTPS 확인
이제 https로 접속이 가능하다.
'T-I-L > [책] 요약&정리' 카테고리의 다른 글
| [점프 투 스프링부트] 3장 SBB 서비스 개발(SSL) - 2023. 09. 20. (0) | 2023.09.25 |
|---|---|
| [점프 투 스프링부트] 3장 SBB 서비스 개발(도메인) - 2023. 09. 20. (0) | 2023.09.21 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(로깅) - 2023. 09. 20. (0) | 2023.09.20 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(NGINX) - 2023. 09. 19. (0) | 2023.09.19 |
| [점프 투 스프링부트] 3장 SBB 서비스 개발(개발과 서버 환경 분리) - 2023. 09. 15. (0) | 2023.09.15 |
