From 45ef2c4b58ef61e0228e6307f8256ecf9fc98343 Mon Sep 17 00:00:00 2001 From: xoliqberdiyev Date: Thu, 25 Dec 2025 10:55:48 +0000 Subject: [PATCH] Update Dockerfile --- Dockerfile | 73 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5cdbd9..812f19f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,37 +13,58 @@ COPY . . # Environment variables (agar kerak bo'lsa) ENV NEXT_TELEMETRY_DISABLED=1 -# Next.js build +# Next.js static export RUN npm run build -# Production stage -FROM node:22-alpine AS runner +# Production stage - Nginx +FROM nginx:alpine -WORKDIR /app +# Default html tozalaymiz +RUN rm -rf /usr/share/nginx/html/* -ENV NODE_ENV=production -ENV PORT=3000 +# ❗ MUHIM: Next.js static export - out papka +COPY --from=builder /app/out /usr/share/nginx/html -# Next.js uchun zarur foydalanuvchi yaratish -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nextjs -u 1001 +# Default nginx configni o'chiramiz +RUN rm /etc/nginx/conf.d/default.conf -# Package.json va node_modules nusxalash -COPY --from=builder /app/package*.json ./ -COPY --from=builder /app/node_modules ./node_modules +# nginx.conf ni bevosita Dockerfile ichida yozamiz +RUN printf '%s\n' \ +'server {' \ +' listen 80;' \ +' server_name _;' \ +'' \ +' root /usr/share/nginx/html;' \ +' index index.html;' \ +'' \ +' # Gzip compression' \ +' gzip on;' \ +' gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript;' \ +'' \ +' # Cache static assets' \ +' location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {' \ +' expires 1y;' \ +' add_header Cache-Control "public, immutable";' \ +' }' \ +'' \ +' # Next.js _next static files' \ +' location /_next/static/ {' \ +' expires 1y;' \ +' add_header Cache-Control "public, immutable";' \ +' }' \ +'' \ +' # SPA routing - barcha requestlarni index.html ga yo'\''naltirish' \ +' location / {' \ +' try_files $uri $uri/ $uri.html /index.html;' \ +' }' \ +'' \ +' # Security headers' \ +' add_header X-Frame-Options "SAMEORIGIN" always;' \ +' add_header X-Content-Type-Options "nosniff" always;' \ +' add_header X-XSS-Protection "1; mode=block" always;' \ +'}' \ +> /etc/nginx/conf.d/default.conf -# Build qilingan fayllarni nusxalash -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/public ./public +EXPOSE 80 -# next.config kerak bo'lsa -COPY --from=builder /app/next.config.* ./ - -# Foydalanuvchi huquqlarini o'zgartirish -RUN chown -R nextjs:nodejs /app - -USER nextjs - -EXPOSE 3000 - -CMD ["npm", "start"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file