## default.conf ##

# 1. HTTP → HTTPS 리디렉션

server {
    listen 80;
    server_name [도메인 주소];

    return 301 https://$host$request_uri;
}

# 2. HTTPS 서버 구성

server {
    listen 443 ssl;
    server_name [도메인 주소];

    ssl_certificate /etc/letsencrypt/live/[도메인 주소]/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/[도메인 주소]/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

  
    # [포트: 443] - 정적 파일 서빙 (React 앱)
    
    root /usr/share/nginx/html;
    index index.html;

    location / {
        try_files $uri /index.html;
    }

    # [프록시: API 요청 → Spring Boot 서버 (:8080)]

    location /api/ {
        proxy_pass <http://localhost:8080>;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
    }

    # [프록시: WebSocket 요청 → Spring 서버 (:8080)]

    location /ws/ {
        proxy_pass <http://localhost:8080>;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
    }
}
## Dockerfile ##

# 1단계: 빌드 스테이지
FROM node:18-alpine AS build

WORKDIR /app

# package.json, package-lock.json 복사
COPY package*.json ./

# 의존성 설치
RUN npm install

# 소스 복사 후 빌드
COPY . .
RUN npm run build

# 2단계: Nginx로 정적 파일 서빙
FROM nginx:1.25-alpine

# Nginx 기본 설정 파일 삭제
RUN rm /etc/nginx/conf.d/default.conf

# 사용자 설정 파일 복사
COPY default.conf /etc/nginx/conf.d/

# Vite 빌드 결과물을 Nginx 루트로 복사
COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
# Node.js 20으로 업데이트
FROM node:20 AS build

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

RUN npm run build

FROM nginx:alpine

COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/default.conf

RUN mkdir -p /etc/letsencrypt/live && mkdir -p /etc/letsencrypt/archive

COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]