✏️본 포스트는 HTTPS 설정하는 과정을 기록한 것입니다.
또한 본 글은 다음 포스트를 참고하였습니다!
09. https 도메인 연결하기 Draconist
이번 프로젝트는 react native로 애플리케이션을 만드는 것이었기 때문에 https 설정이 필요했습니다.제일 처음 찾아봤던 방법은 aws route53을 이용하는 것이었습니다.제가 진행했던 프로젝트는 규모
turtle0204.tistory.com
⭐AWS route 53 도메인 설정
일단 HTTPS 설정을 하기 위해선 AWS에서 route53 도메인 설정을 먼저 진행해야합니다.

2) 그 다음 타사이트에서 구매한 도메인을 입력한 다음 호스팅 영역을 생성해줍니다.
호스팅 영역 생성 결과는 다음과 같습니다.
구매한 도메인 이름을 입력하고, 유형은 공개 호스팅 영역(Public Hosted Zone) 으로 선택한 뒤 생성합니다.

3) 다음과 같이 호스팅 영역이 생성이 되면 유형 NS와 SOA를 가진 같은 레코드가 2개 생깁니다.
이 값들을 도메인 구입한 사이트(예: 가비아, 카페24, Namecheap 등)의 DNS 설정 페이지에 붙여넣습니다.
aws의 NS 타입 의 값/트래픽 라우팅 대상 값들을 뒤에 . 빼고 다 넣고 적용해주어야 합니다.
4) 이제 실제 사용가능하게 도메인을 생성해야합니다.
레코드에 이름을 붙이면 도메인앞에 추가로 붙습니다. 따로 레코드를 붙이고 싶지 않다면 빈칸으로 생성해도 됩니다.
값엔 EC2에서 생성한 고정 ip주소값을 넣으면 됩니다.

이후 A 유형으로 만들어지고 적용 되는데까지 시간이 조금 걸립니다.
이제 도메인이 EC2에 연결되었습니다. 이후 HTTPS 설정(Certbot + Nginx) 또는 AWS Certificate Manager + Load Balancer 등을 통해 보안 인증서를 적용할 수 있습니다.
⭐HTTPS 도메인 연결 과정
1) 우선 HTTPS 설정을 진행하기 전에 NGINX 설치를 진행합니다.
sudo apt update
sudo apt install nginx
#확인 명령어
systemctl status nginx

💠 NGINX란?
Nginx(엔진엑스)는 “높은 동시 처리 성능”과 “비동기 이벤트 기반 아키텍처”를 특징으로 하는 경량 웹 서버입니다.
원래는 정적 파일 처리에 최적화된 웹 서버로 시작했지만, 지금은 리버스 프록시, 로드 밸런서, SSL 터미네이션, API 게이트웨이 등의 다양한 용도로 사용됩니다.
Nginx의 주요 역할
1. 웹 서버 | HTML, CSS, JS, 이미지 등 정적 파일을 빠르게 제공 |
2. 리버스 프록시 서버 | 사용자의 요청을 내부 서버(예: Spring, Node.js)로 전달하고, 응답을 사용자에게 전달 |
3. 로드 밸런서 | 여러 개의 서버로 트래픽을 분산하여 부하 분산 처리 |
4. HTTPS 게이트웨이 | SSL 인증서 적용을 통해 HTTPS(보안 통신) 처리 가능 |
5. 캐시 서버 | 응답 결과를 캐싱하여 서버 부담을 줄이고 속도를 향상 |
Nginx가 자주 사용되는 이유
- 빠른 속도 (특히 정적 파일 처리에 강함)
- 낮은 메모리 사용량
- 설정 유연성 (가상 호스트, 리버스 프록시, 캐시 등)
- SSL 인증서 설정 용이 (certbot과 연동 가능)
- Docker, AWS, Kubernetes 등 클라우드 환경과 잘 어울림
2) Ubuntu 기반 리눅스 서버에서 HTTPS 인증서 발급을 위한 Certbot 및 Nginx 연동 플러그인을 설치하는 명령어입니다.
sudo apt-get install certbot python3-certbot-nginx
sudo | 관리자 권한으로 명령 실행 |
apt-get install | APT 패키지 매니저를 통해 소프트웨어 설치 |
certbot | Let's Encrypt 인증서를 발급·갱신하는 클라이언트 도구 |
python3-certbot-nginx | Certbot이 Nginx 서버 설정과 연동되도록 지원하는 플러그인 |
- HTTPS(보안 연결) 를 적용하려면 인증서가 필요합니다.
- 인증서를 무료로 제공하는 기관 중 하나가 Let's Encrypt입니다.
- certbot은 Let's Encrypt 인증서를 쉽게 발급받고 자동 갱신해주는 도구입니다.
- python3-certbot-nginx는 Nginx 설정을 자동 감지하고, server 블록에 SSL 설정을 자동 삽입해줍니다.
3) Nginx SSL 설정을 진행합니다.
SSL 인증서를 발급 받은 후 웹 서버(Nginx)에서 브라우저에 전달할 SSL 인증서 정보를 설정해야 합니다.
아까 다운로드한 Let’s Encrypt 클라이언트를 통해 인증서 발급 시 자동으로 SSL 설정이 가능하므로, Nginx 경로에 대한 설정만 해주면 됩니다.
Nginx 기본 설정 파일 수정하려면 다음과 같은 명령어를 입력합니다.
sudo vi /etc/nginx/sites-enabled/default
💠 server_name 수정
기존 설정에서 server_name _; 라고 되어 있는 부분을 발급받은 도메인으로 변경합니다.

# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name goodluckynews.store;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/goodluckynews.store/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/goodluckynews.store/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
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
server {
if ($host = goodluckynews.store) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name goodluckynews.store;
return 404; # managed by Certbot
}
4) Certbot 설치 및 인증서 발급
🔹 인증서 발급 및 자동 구성
sudo certbot --nginx -d goodluckynews.store
이메일 입력 및 약관 동의 후 인증 성공 시 자동으로 /etc/nginx/sites-enabled/default에 SSL 관련 설정이 추가됩니다.
5) Nginx HTTPS 설정 확인 및 리버스 프록시 설정
🔹 /etc/nginx/sites-enabled/default의 설정 예시
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name goodluckynews.store;
ssl_certificate /etc/letsencrypt/live/draconist.goodluckynews.store/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/draconist.goodluckynews.store/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# Spring 서버로 프록시
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $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;
}
}
6) HTTP → HTTPS 리다이렉션 설정
server {
listen 80;
listen [::]:80;
server_name goodluckynews.store;
return 301 https://$host$request_uri;
}
7) 설정 테스트 및 재시작
sudo nginx -t
sudo systemctl restart nginx
nginx -t 명령어로 문법 오류를 먼저 확인한 뒤 재시작하시면 됩니다.
이제 설정한 사이트로 로 접속하면 SSL이 적용된 안전한 웹사이트를 사용할 수 있습니다.
'🏃♀️ 대외활동 > Draconist - 소모임' 카테고리의 다른 글
[Draconist] Docker 및 github action CI/CD하기 (0) | 2025.07.24 |
---|---|
[Draconist] Docker 이미지 빌드하기 (2) | 2025.07.23 |
[Draconist] EC2 설정 및 RDS 연결 (1) | 2025.07.19 |