# Multi-stage build for optimized nginx image FROM nginx:alpine # Remove default nginx static assets RUN rm -rf /usr/share/nginx/html/* # Copy static files COPY index.html /usr/share/nginx/html/ COPY project-mode.html /usr/share/nginx/html/ COPY shop-mode.html /usr/share/nginx/html/ # Create a custom nginx configuration for better caching and security RUN cat > /etc/nginx/conf.d/default.conf <<'EOF' server { listen 80; server_name _; root /usr/share/nginx/html; index 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; add_header Referrer-Policy "no-referrer-when-downgrade" always; # Gzip compression gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; # Cache static assets location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; } # Main location location / { try_files $uri $uri/ /index.html; } # Health check endpoint location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } } EOF # Run nginx as non-root user RUN chown -R nginx:nginx /usr/share/nginx/html && \ chown -R nginx:nginx /var/cache/nginx && \ chown -R nginx:nginx /var/log/nginx && \ touch /var/run/nginx.pid && \ chown -R nginx:nginx /var/run/nginx.pid USER nginx # Expose port 80 EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --quiet --tries=1 --spider http://localhost/health || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"]