diff --git a/Dockerfile b/Dockerfile index 055487b..4361af5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,14 +12,17 @@ COPY . . # Build the site with verbose output RUN hugo --minify +# Pre-compress files for nginx gzip_static +RUN find /app/public -type f \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.xml' -o -name '*.json' -o -name '*.svg' -o -name '*.woff' -o -name '*.woff2' -o -name '*.ttf' -o -name '*.otf' -o -name '*.eot' \) -exec gzip -k -9 {} \; + # Production stage FROM nginx:alpine # Copy the built site from builder COPY --from=builder /app/public /usr/share/nginx/html -# Copy custom nginx config if needed -# COPY nginx.conf /etc/nginx/conf.d/default.conf +# Copy custom nginx config +COPY nginx.conf /etc/nginx/conf.d/default.conf # Expose port 80 EXPOSE 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..33c7782 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 80; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + # Serve pre-compressed files + gzip_static on; + + # Enable dynamic gzip as fallback + gzip on; + gzip_vary on; + gzip_min_length 1024; + 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; + + location / { + try_files $uri $uri/ =404; + } +} +