diff --git a/docker/Dockerfile b/docker/Dockerfile index 8abfcc7..6f866df 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,13 +5,18 @@ RUN npm install COPY . . RUN npm run build -FROM node:18-alpine +FROM nginx:alpine WORKDIR /app -COPY --from=builder /app/.output ./.output -COPY --from=builder /app/package*.json ./ -COPY --from=builder /app/public ./public -COPY --from=builder /app/.nuxt ./.nuxt -RUN npm install --production -ENV NODE_ENV=production -EXPOSE 3000 -CMD ["node", ".output/server/index.mjs"] + +# Copy nginx configuration +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf + +# Copy built application +COPY --from=builder /app/.output /app/.output +COPY --from=builder /app/public /app/public + +# Expose port +EXPOSE 80 + +# Start nginx +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..c5da201 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,46 @@ +server { + listen 80; + server_name localhost; + + root /app/.output/public; + index index.html; + + # Proper MIME type handling + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Security headers + add_header X-Content-Type-Options nosniff; + add_header X-Frame-Options SAMEORIGIN; + add_header X-XSS-Protection "1; mode=block"; + + location / { + try_files $uri $uri/ /index.html; + } + + # Handle static files + location /_nuxt/ { + alias /app/.output/public/_nuxt/; + expires 1y; + add_header Cache-Control "public, no-transform"; + try_files $uri =404; + } + + # Handle other static files + location /public/ { + alias /app/public/; + expires 1y; + add_header Cache-Control "public, no-transform"; + try_files $uri =404; + } + + # Handle API requests + location /api/ { + proxy_pass http://localhost:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } +} \ No newline at end of file