Static File Serving with Caching

1 min read

Authors
banner

Static File Serving

Production Config

server {
    root /var/www/static;

    location / {
        try_files $uri =404;
    }

    # Cache assets 1 year
    location ~* \.(js|css|png|jpg|svg)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Compress
    gzip on;
    gzip_types text/css application/javascript;
}

Blazing fast!

© 2025 Vijay Rajendran