Multi-stage build: Node.js 22 for Astro build, nginx:alpine for serving. Includes gzip, security headers, and immutable cache for _astro/ assets.
68 lines
1.6 KiB
Nginx Configuration File
68 lines
1.6 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 X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_min_length 256;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/javascript
|
|
application/javascript
|
|
application/json
|
|
application/xml
|
|
image/svg+xml
|
|
font/woff2;
|
|
|
|
# Astro hashed assets — immutable cache
|
|
location /_astro/ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
access_log off;
|
|
}
|
|
|
|
# Static files
|
|
location ~* \.(ico|svg|png|jpg|jpeg|webp|gif|woff2?|ttf|eot)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public";
|
|
access_log off;
|
|
}
|
|
|
|
# CSS/JS
|
|
location ~* \.(css|js)$ {
|
|
expires 7d;
|
|
add_header Cache-Control "public";
|
|
}
|
|
|
|
# Main location — clean URLs (Astro generates /page/index.html)
|
|
location / {
|
|
try_files $uri $uri/ $uri.html /index.html =404;
|
|
}
|
|
|
|
# Deny hidden files
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# Custom error pages
|
|
error_page 404 /404.html;
|
|
location = /404.html {
|
|
internal;
|
|
}
|
|
}
|