78 lines
2.2 KiB
Plaintext
78 lines
2.2 KiB
Plaintext
# Nginx server configuration for Storybook static site
|
|
server {
|
|
listen 8080;
|
|
listen [::]:8080;
|
|
server_name _;
|
|
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Security headers for Storybook
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
# Storybook needs more permissive CSP for iframe and scripts
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self' ws: wss:; frame-src 'self';" always;
|
|
|
|
# Caching strategy for static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header Vary "Accept-Encoding";
|
|
access_log off;
|
|
}
|
|
|
|
# Caching for HTML files (shorter cache time)
|
|
location ~* \.html$ {
|
|
expires 1h;
|
|
add_header Cache-Control "public, must-revalidate";
|
|
add_header Vary "Accept-Encoding";
|
|
}
|
|
|
|
# Main location block for Storybook
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# Handle Storybook's client-side routing
|
|
# Always fall back to index.html for SPA behavior
|
|
}
|
|
|
|
# Storybook static assets
|
|
location /static/ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header Vary "Accept-Encoding";
|
|
access_log off;
|
|
}
|
|
|
|
# Storybook specific directories
|
|
location ~ ^/(sb-|assets/|fonts/) {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header Vary "Accept-Encoding";
|
|
access_log off;
|
|
}
|
|
|
|
# Deny access to sensitive files
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# Health check endpoint
|
|
location /health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# Custom error pages
|
|
error_page 404 /index.html;
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
internal;
|
|
}
|
|
}
|