HTTPS 적용 - showMeTheMoneyPrac/BE_Repo GitHub Wiki

1️⃣ HTTPS를 적용한 이유?

HTTP는 정보를 텍스트로 주고 받기 때문에 네트워크에서 전송 신호를 인터셉트 하는 경우 원하지 않는 데이터 유출이 발생할 수 있다. 이러한 보안 취약점을 해결하기 위한 프로토콜이 HTTP에 S(Secure Socket)가 추가된 것이HTTPS이다.

이번 프로젝트의 경우 Nginx에서 제공하는 certbot라이브러리를 사용하여 SSL인증서를 발급받아 HTTPS를 적용하였다.

2️⃣ 활용 방법

  • 배포환경
    • AWS EC2 (Ubuntu 18.0)
    • .jar 의 spring boot 어플리케이션
server {
  listen 80; #80포트로 받을 때 https로 리다이렉션
  server_name john3210.shop; #도메인주소, 없을경우 localhost
  return 301 https://john3210.shop$request_uri;

}
server {
	#https 요청을 리스닝.
	  listen 443 ssl http2;

  # ssl 인증서 적용하기
  ssl_certificate /etc/letsencrypt/live/john3210.shop/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/john3210.shop/privkey.pem;

  location / 
    proxy_pass http://localhost:8080; # Request에 대해 어디로 리다이렉트하는지 작성. 
																			# 8443 -> 자신의 springboot app이사용하는 포트
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}
server {
    if ($host = john3210.shop) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

  listen 80;
  server_name john3210.shop;
    return 404; # managed by Certbot

}

서버 주소로 접근시에 배포한 https URL로 리다이렉트 되는것을 확인 할 수 있었다.

참고 문헌

https://curryyou.tistory.com/207

[https://velog.io/@jihyunhillpark/2.-spring-boot-기반-앱-배포-Cerbot-인증서-발급과-SSL-적용](https://velog.io/@jihyunhillpark/2.-spring-boot-%EA%B8%B0%EB%B0%98-%EC%95%B1-%EB%B0%B0%ED%8F%AC-Cerbot-%EC%9D%B8%EC%A6%9D%EC%84%9C-%EB%B0%9C%EA%B8%89%EA%B3%BC-SSL-%EC%A0%81%EC%9A%A9)

https://www.fntec.net/article.php?no=220

https://nuritech.tistory.com/25