Skip to content

Instantly share code, notes, and snippets.

@aeldar
Last active March 14, 2024 15:46
Show Gist options
  • Save aeldar/9d2837d6da42299179a548bce4955eef to your computer and use it in GitHub Desktop.
Save aeldar/9d2837d6da42299179a548bce4955eef to your computer and use it in GitHub Desktop.
Nginx configuration for a microfrontend inside SingleSPA
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location /healthz.html {
add_header Cache-Control "no-store, max-age=0"; # never cache
}
location /index.html {
add_header Cache-Control "no-store, max-age=0"; # never cache
}
location = /main.js {
add_header Cache-Control no-cache; # always revalidate
}
location = /assets/js/env.js {
add_header Cache-Control no-cache; # always revalidate
}
# aggressively cache files fingerprinted by Angular
location ~* ".+\.[0-9a-f]{20}\.(?:css|js|woff|woff2|gif|png|jpg|jpeg|svg|webp)$" {
expires 1y; # one year
add_header Cache-Control public;
}
# cache everything else for some short period
location / {
try_files $uri $uri/ /index.html?$args;
expires 2h; # two hours
add_header Cache-Control public;
}
# Compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml image/svg+xml application/xml application/xml+rss text/javascript;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment