Added stream compression for static content in docker after the hugo build process.

This commit is contained in:
Jeremy Karst 2026-01-07 18:33:15 -05:00
parent 7db7b95734
commit 4cfcb45a7d
2 changed files with 26 additions and 2 deletions

View file

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

21
nginx.conf Normal file
View file

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