From cf735f31bf664d07d8e12f826e46abcf0601e8dd Mon Sep 17 00:00:00 2001 From: HieuPQ <“phamquanghieu9x@gmail.com”> Date: Tue, 12 Aug 2025 15:22:56 +0700 Subject: [PATCH] Add docker file and nginx config --- Dockerfile | 25 +++++++++++++++++++++++++ nginx/nginx.conf | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5dcae0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +ARG NODE_VERSION=22.14.0 + +FROM node:${NODE_VERSION}-alpine AS development + +WORKDIR /app + +RUN --mount=type=cache,target=/root/.npm +COPY package.json . +COPY package-lock.json . + +RUN npm install + +COPY . . + +RUN npm run build + +FROM nginx:alpine AS production + +COPY --from=development /app/dist /usr/share/nginx/html + +COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +ENTRYPOINT [ "nginx", "-g", "daemon off;" ] \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..5f62934 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + + root /usr/share/nginx/html; + # Default file to serve for directory requests + index index.html index.htm; + + location / { + # Try to serve the requested file directly ($uri) + # If it's a directory, try serving the index file ($uri/) + # If neither exists, fall back to serving /index.html + try_files $uri $uri/ /index.html; + } + + # Optional: Add cache control headers for static assets for better performance + location ~* \.(?:css|js|jpg|jpeg|gif|png|ico|svg|webp)$ { + expires 1y; + add_header Cache-Control "public"; + access_log off; # Optional: Don't log accesses for static files + } +}