Add docker file and nginx config

This commit is contained in:
HieuPQ 2025-08-12 15:22:56 +07:00
parent 3dddb0af8d
commit cf735f31bf
2 changed files with 46 additions and 0 deletions

25
Dockerfile Normal file
View File

@ -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;" ]

21
nginx/nginx.conf Normal file
View File

@ -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
}
}