
Private Subnet에 있는 Resource(EC2 instance)들이 인터넷(외부)에 통신할 수 있게 해주는 장치
약자 정리
- VPC 생성 :
- 이름 : xx-PRD-VPC
- IPv4 CIDR : 10.17.0.0/16
- AZ : 2A
- Subnet :
- xx-PRD-VPC-NGINX-PUB-2A (10.17.0.0/24)
- xx-PRD-VPC-WAS-PRI-2A (10.17.1.0/24)
- xx-PRD-VPC-DB-PRI-2A (10.17.2.0/24)
- xx-PRD-VPC-BASTION-PUB-2A (10.17.3.0/24)
- Routing table :
- xx-PRD-RT-PUB : NGINX, BASTION
- xx-PRD-VPC-NGINX-PUB-SG-2A
- xx-PRD-VPC-BASTION-PUB-SG-2A
- xx-PRD-RT-PRI : DB, WAS
- xx-PRD-VPC-WAS-PRI-SG-2A
- xx-PRD-VPC-DB-PRI-2A
- IGW
- xx-PRD-IGW
> 0.0.0.0/0 Routing 추가 (PUB)
- SG
- xx-PRD-VPC-NGINX-PUB-SG-2A = 22, 80
- xx-PRD-VPC-BASTION-PUB-SG-2A = 22
- xx-PRD-VPC-WAS-PRI-SG-2A = 22, 8000
- xx-PRD-VPC-DB-PRI-2A = 22, 3306
- NAT G/W
- xx-PRD-NGW-2A
- xx-PRD-VPC-NGINX-PUB-2A
- Public
- Elastic IP 할당











yslee-PRD-VPC-BASTION-PUB-2A-00
yslee-PRD-VPC-NGINX-PUB-2A-00
yslee-PRD-VPC-WAS-PRI-2A-00
yslee-PRD-VPC-DB-PRI-2A-00
Ubuntu 24.04
t3.micro
yslee-01
퍼블릭 IP를 설정하는거 집중!
yslee-PRD-VPC-BASTION-PUB-2A-00 : 퍼블릭 IP 활성화
yslee-PRD-VPC-NGINX-PUB-2A-00 : 퍼블릭 IP 활성화
yslee-PRD-VPC-WAS-PRI-2A-00 : 퍼블릭 IP 비활성화
yslee-PRD-VPC-DB-PRI-2A-00 : 퍼블릭 IP 비활성화

BASTION
Private 10.17.0.180
Public 43.203.224.157
NGINX
Private 10.17.1.156
Public 3.35.173.237
WAS
Private 10.17.2.44
Public -
DB
Private 10.17.3.15
Public -


sudo passwd root
apt update
apt install -y git
git clone https://github.com/Joes-s/fastapi-3tier.git

scp -i yslee-01.pem yslee-01.pem ubuntu@43.203.224.157:/home/ubuntu
# 거부 당할 경우 권한
icacls.exe yslee-01.pem /grant:r %user
icacls.exe yslee-01.pem /inheritance:r


# NGINX 접속
ssh -i yslee-01.pem ubuntu@10.17.1.156
# WAS 접속
ssh -i yslee-01.pem ubuntu@10.17.2.44
# DB 접속
ssh -i yslee-01.pem ubuntu@10.17.3.15

# NGINX로 보내기
scp -i yslee-01.pem -r fastapi-3tier ubuntu@10.17.1.156:/home/ubuntu/
# WAS로 보내기
scp -i yslee-01.pem -r fastapi-3tier ubuntu@10.17.2.44:/home/ubuntu/
# DB로 보내기
scp -i yslee-01.pem -r fastapi-3tier ubuntu@10.17.3.15:/home/ubuntu/
# 권한 문제 발생시
chmod 400 yslee-01.pem
# 업데이트 하고 nginx를 설치한다.
sudo apt update
sudo apt install nginx -y
# html 파일 부분에 옮긴다.
sudo cp -r ~/fastapi-3tier/* /var/www/html/
# 권한을 부여한다.
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

conf.dd에 컨피그 파일을 넣어줘야한다.cd /etc/nginx/conf.d
vi default.conf
# 작성 내용
upstream was {
server 10.17.2.44:8000;
}
server {
listen 80;
server_name _;
# 정적 파일 경로 (HTML, CSS, JS, Images)
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://was;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;
}
location ~* \.(py|sql|md|git|sh)$ {
deny all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# 오타 검사
sudo nginx -t
# Reload
sudo systemctl reload nginx

2026/03/27 07:09:25 [warn] 14797#14797: conflicting server name "_" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# 파일 확인해서 삭제해야함.
sudo rm /etc/nginx/sites-enabled/default
sudo apt install python3-venv -y
python3 -m venv venv
source venv/bin/activate
# 패키지 설치
pip install fastapi sqlalchemy pymysql python-multipart uvicorn

sudo apt install python3-venv -y
python3 -m venv venv
source venv/bin/activate
# mariadb 설치
sudo apt install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl status mariadb
# 접속
mariadb -u root -p -e "CREATE DATABASE IF NOT EXISTS WebTest;"
mariadb -u root -p WebTest < webtest_DB.sql
# 생성 확인
sudo mariadb -u root -p
USE WebTest;





