Static file serving

Configuring Ferron as a static file server is straightforward — you just need to specify the directory containing your static files using the root directive. To configure Ferron as a static file server, you can use the configuration below:

example.com {
    root /var/www/html
}

HTTP compression for static files

HTTP compression for static files is enabled by default. To disable it, you can use this configuration:

example.com {
    root /var/www/html
    compressed false
}

Directory listings

Directory listings are disabled by default. To enable them, you can use this configuration:

example.com {
    root /var/www/html
    directory_listing
}
Tip

If you get 404 Not Found for files that should exist, verify the root path is correct and readable by the user running Ferron.

Single-page applications

Single-page applications (SPAs) are also supported by Ferron by adding a URL rewrite rule in addition to the static file serving configuration. You can use this configuration:

example.com {
    root /var/www/html
    rewrite "^/.*" "/" {
        last
        directory false
        file false
    }
}
Tip

If SPA routes (for example /dashboard/settings) return 404 Not Found, add the rewrite rule from the SPA section so unknown paths fall back to /.

Static file serving with caching headers

Ferron supports setting Cache-Control headers for static files. To enable caching headers for static files, you can use this configuration:

example.com {
    root /var/www/html
    etag
    file_cache_control "public, max-age=3600"
}
Tip

If responses look stale while using file_cache_control, reduce cache lifetime or temporarily disable caching while debugging.

Serving precompressed static files

Ferron supports serving precompressed static files (sidecar files like app.js.gz, app.js.br). To enable this feature, you can use this configuration:

example.com {
    root /var/www/html
    precompressed
}

In this configuration, Ferron will serve precompressed versions of static files if they exist. The precompressed static files would additionally have .gz extension for gzip, .br for Brotli, .deflate for Deflate, or .zst for Zstandard.

Tip

If precompressed assets are not served, check that matching files exist (for example app.js.br or app.js.gz) and regenerate them after changing source assets.