S3와 Docker 없이 동일한 EC2에 FastAPI, SpringBoot 배포하기
1. 동일한 EC2에 FastAPI, Spring Boot 프로젝트 git clone
[AWS] AWS로 Spring Boot 배포 3/ java jar 파일 빌드/ git clone/ EC2 Timezone KST로 변경/ 서버 날짜 설정
실행 방법 2가지 jar 파일 빌드 -> EC2 복사 EC2에서 프로젝트 git clone 1. jar 파일 빌드 -> EC2 복사 JDK 설치 $ sudo apt-get update $ sudo apt-get install openjdk-17-jdk Spring Boot 프로젝트 빌드 프로젝트 파일 위치로
debug.tistory.com
[AWS] AWS로 Fast API 배포/ Python/ Uvicorn/ 백그라운드 실행/ 주식 데이터/ 주식 라이브러리/ FinanceDataRead
패키지 설치Python, FastAPI, Uvicorn 설치$ sudo apt-get install python3-pip$ sudo apt-get pip3 install fastapi$ sudo apt-get pip3 install uvicorn데이터 유효성 검사 및 설정 관리pip install pydantic.env 파일 관리pip install python-dote
debug.tistory.com
2. 동시 배포(Nginx)
nginx를 reverse proxy server로 활용
- 클라이언트 요청 -> 백엔드 서버(Spring Boot/ FastAPI)로 전달
- / 백엔드 서버로부터 받은 응답 -> 클라이언트에 반환
nginx 설치
$ sudo apt-get update
$ sudo apt-get install nginx
설정 파일 생성 및 편집
// sudo vi /etc/nginx/sites-available/{프로젝트명}.conf
sudo vi /etc/nginx/sites-available/tusori.conf
설정 파일 내용
server {
// nginx가 80번 포트에서 HTTP 요청 수신
listen 80;
server_name {탄력적 IP};
location /springBoot/ {
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;
}
location /fastapi/ {
proxy_pass http://localhost:8000/;
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;
}
}
설정 파일 활성화 -> 심볼릭 링크 생성
// sudo ln -s /etc/nginx/sites-available/{프로젝트명}.conf /etc/nginx/sites-enabled/{프로젝트명}.conf
sudo ln -s /etc/nginx/sites-available/tusori.conf /etc/nginx/sites-enabled/tusori.conf
*심볼릭 링크: 특정 파일이나 디렉토리에 대한 참조(포인터) 역할
실제 파일: sites-available 디렉토리에 위치 But, sites-enabled 디렉토리에서 참조
3. 설정 적용 및 nginx 재시작
설정 테스트
sudo nginx -t
nginx 다시 로드 -> 변경사항 적용
sudo systemctl reload nginx
nginx 재시작
sudo systemctl restart nginx
참고
GitHub - Tu-Sori/Tusori-Backend: [Java] 투자 기초 설명서
[Java] 투자 기초 설명서. Contribute to Tu-Sori/Tusori-Backend development by creating an account on GitHub.
github.com