diff --git a/docker-compose.yml b/docker-compose.yml index 19acc63..a0a07c7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: build: ./frontend container_name: mc-filter-frontend expose: - - "3000" + - "80" restart: unless-stopped networks: - mc-filter diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 065c73e..c1f7de5 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,4 +1,4 @@ -# 빌드 단계 +# 빌드 단계: vite 로 dist/ 만든다 FROM node:20-alpine AS build WORKDIR /app COPY package.json ./ @@ -6,12 +6,10 @@ RUN npm install --no-audit --no-fund COPY . ./ RUN npm run build -# 서빙 단계: vite preview 로 dist/ 정적 서빙 -FROM node:20-alpine -WORKDIR /app -COPY --from=build /app/package.json ./ -COPY --from=build /app/node_modules ./node_modules -COPY --from=build /app/dist ./dist -COPY --from=build /app/vite.config.js ./ -EXPOSE 3000 -CMD ["npx", "vite", "preview", "--host", "0.0.0.0", "--port", "3000"] +# 서빙 단계: nginx 가 정적으로 dist/ 를 서빙한다. +# (vite preview 는 dev/preview 용이고 docker production 환경에서 연결 끊김 +# 현상이 보고된 적이 있어 nginx 정적 서빙으로 통일) +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..a0b4e24 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,20 @@ +server { + listen 80 default_server; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # 정적 자산 캐시 (해시가 붙은 vite 산출물) + location /assets/ { + access_log off; + expires 30d; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } + + # SPA fallback: 브라우저에서 /domains 같은 경로를 새로고침 해도 index.html 을 반환 + location / { + try_files $uri $uri/ /index.html; + } +}