Multi-stage Dockerfile: node:22.13.1-alpine3.21 builds the Vite bundle, nginx:1.27.4-alpine3.21-slim serves dist/ on container :80. Compose maps host :4422 to container :80 with a wget healthcheck and unless-stopped restart policy. nginx.conf serves Vite's content-addressed /assets/ as immutable, caches images for 30d, falls back to index.html for SPA routes, and sets X-Frame-Options / X-Content-Type-Options / Referrer-Policy / Permissions-Policy headers. Server tokens off. .dockerignore keeps the build context lean (no node_modules, dist, .git, archive, or compose files). Pin to image digests in Portainer's stack editor for full lock. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
45 lines
1.2 KiB
Nginx Configuration File
45 lines
1.2 KiB
Nginx Configuration File
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 Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
|
|
|
|
# Hashed asset bundles — long cache, immutable
|
|
location /assets/ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# Public images and other static files
|
|
location ~* \.(?:jpg|jpeg|png|gif|webp|svg|ico|woff2?|ttf)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# SPA fallback — any non-asset path serves index.html so future
|
|
# client-side routing works without 404s.
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Don't serve dotfiles
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
|
|
}
|