diff --git a/Dockerfile.prod b/Dockerfile.prod index 7c169c9..745b56f 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,3 +1,4 @@ +# Stage 1: Build FROM node:lts AS build WORKDIR /app @@ -10,18 +11,23 @@ COPY . . RUN npm run build +# Stage 2: Serve with Nginx FROM nginx:stable-alpine -# 기본 nginx 설정 제거 및 설정 복사 +# Remove default Nginx configuration and copy custom config RUN rm -rf /etc/nginx/conf.d COPY conf /etc/nginx -# 빌드된 파일을 nginx에 복사 +# Copy SSL certificates +COPY path/to/your/ssl/certificates/nginx.crt /etc/nginx/ssl/nginx.crt +COPY path/to/your/ssl/certificates/nginx.key /etc/nginx/ssl/nginx.key + +# Copy built files to Nginx COPY --from=build /app/build /usr/share/nginx/html -# HTTP(80) 및 HTTPS(443) 포트 오픈 +# Expose HTTP and HTTPS ports EXPOSE 80 EXPOSE 443 -# nginx 실행 +# Run Nginx CMD ["nginx", "-g", "daemon off;"] diff --git a/conf/conf.d/default.conf b/conf/conf.d/default.conf index fdc6f51..fec32e3 100644 --- a/conf/conf.d/default.conf +++ b/conf/conf.d/default.conf @@ -2,9 +2,24 @@ server { listen 80; server_name syluv.store www.syluv.store; + # HTTP 요청을 HTTPS로 리디렉션 location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html; + return 301 https://$host$request_uri; } -} \ No newline at end of file +} + +server { + listen 443 ssl; + server_name syluv.store www.syluv.store; + + ssl_certificate /etc/nginx/ssl/nginx.crt; + ssl_certificate_key /etc/nginx/ssl/nginx.key; + + location / { + proxy_pass http://localhost:3000; + 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; + } +}