Added stream compression for static content in docker after the hugo build process.
This commit is contained in:
parent
7db7b95734
commit
4cfcb45a7d
2 changed files with 26 additions and 2 deletions
|
|
@ -12,14 +12,17 @@ COPY . .
|
||||||
# Build the site with verbose output
|
# Build the site with verbose output
|
||||||
RUN hugo --minify
|
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
|
# Production stage
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Copy the built site from builder
|
# Copy the built site from builder
|
||||||
COPY --from=builder /app/public /usr/share/nginx/html
|
COPY --from=builder /app/public /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy custom nginx config if needed
|
# Copy custom nginx config
|
||||||
# COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# Expose port 80
|
# Expose port 80
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
|
||||||
21
nginx.conf
Normal file
21
nginx.conf
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue