[AWS] certbot을 이용한 EC2 https 적용

Eden·2023년 11월 18일
0

Let's Encrypt을 이용하여 무료로 SSL를 발급 받아 https를 적용 시킬 수 있다.

발급된 인증서는 3달간 사용가능하며 갱신을 시켜줘야 계속 사용 가능 하며 인증서를 발급 받기 위해서는 도메인이 필요
또한 EC2 인스턴스의 80,443 포트가 열려있어야함

https 적용 방법

1. AWS EC2 보안 그룹 인바운드 규칙에 80, 443 포트를 열어 준다.

2. Nginx 설치

sudo apt install nginx
sudo service nginx restart

3. Nginx 서버 파일 수정

sudo vi /etc/nginx/sites-available/default
// 예시
server {
  listen 80;
  server_name domain.name;
  location / {
    proxy_pass http://127.0.0.1:3000; // 3000포트의 WAS를 호출
  }
}
sudo service nginx restart

4. certbot 설치

서버로 사용할 EC2 Ubuntu 환경에서 certbot을 설치해야 한다.

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-nginx

5. HTTPS 인증서 만들기

5.1.

$ sudo certbot

5.2.

nginx conf에 사용되고 있는 도메인을 자동으로 탐지해서 보여줄 것이다. 1개 이상의 도메인 중에서 https를 적용시킬 도메인을 선택하면 된다.

5.3.

위와 같은 화면이 떴을 때, 2번을 고르면 된다. 그러면 nginx 설정에 자동으로 https로 리다이렉트 해주는 명령어가 추가 된다.

5.4.

'https://도메인'이 잘 적용됐는지 인터넷을 켜서 해당 주소로 들어가서 확인해보자.

profile
주섬주섬..

0개의 댓글