Skip to content

Commit

Permalink
build: NginX Docker 이미지 생성에 대한 Dockerfile 생성
Browse files Browse the repository at this point in the history
- NginX 이미지 Dockerfile 생성
- NginX 설정 파일 생성

#5
  • Loading branch information
minjungw00 committed Nov 7, 2024
1 parent 261dffc commit 4924122
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM nginx:alpine
WORKDIR /usr/share/nginx/html

# Nginx 기본 설정 복사
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
9 changes: 9 additions & 0 deletions nginx/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM nginx:alpine
WORKDIR /usr/share/nginx/html

# Nginx 기본 설정 복사
COPY ./nginx/default.dev.conf /etc/nginx/conf.d/default.conf

# 정적 파일을 호스트에서 복사 (개발 환경에서 핫 리로딩 사용 가능)
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
32 changes: 32 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 백엔드 서버 정의
upstream backend {
server backend:3000; # 백엔드 서버 (NestJS)
}

server {
listen 80;

# /api 경로로 들어오는 요청은 백엔드로 전달
location /api {
proxy_pass http://backend; # 백엔드로 요청 전달
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;
}

# 정적 파일을 제공하는 기본 경로 설정
location / {
root /usr/share/nginx/html; # React 빌드 결과물이 위치한 디렉터리
index index.html; # 기본 진입점 파일
try_files $uri /index.html; # SPA 라우팅 지원
}

# 404 에러 페이지 설정
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
}
36 changes: 36 additions & 0 deletions nginx/default.dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 백엔드와 프론트엔드에 대한 업스트림 서버 정의
upstream backend {
server backend:3000; # 백엔드 서버 (NestJS)
}

upstream frontend {
server frontend:5173; # 프론트엔드 서버 (React)
}

server {
listen 80;

# /api 경로로 들어오는 요청은 백엔드로 전달
location /api {
proxy_pass http://backend; # 백엔드로 요청 전달
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;
}

# 기본 경로는 프론트엔드로 전달
location / {
proxy_pass http://frontend;
}

# /sockjs-node 경로 (React의 핫 리로딩 웹소켓 연결)
location /sockjs-node {
proxy_pass http://frontend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}

0 comments on commit 4924122

Please sign in to comment.