Static Files
Volucer can serve static files from each site's document root, including directory indexes and precompressed assets.
It is on by default
Static-file serving is enabled by default for each site. No additional configuration is required.
The static layer handles paths that resolve to real, non-script files. Paths that do not
resolve to a file, and paths that name a .php script, continue to the front controller
as before. Enabling static serving therefore does not change how front-controller
applications handle those requests.
Turning it off
[server]
static_files = false
serve_only = "backend" has the same effect. When all other options use their defaults,
static_files = true is shorthand for enabled = true.
Static files are served over HTTP. Volucer rejects an explicit static-file configuration
when no server.http listener is configured. Omitting the setting does not enable static
serving on a FastCGI-only deployment.
A files-only site
A files-only site does not need a backend. A listener, document root, and
serve_only = "static" are sufficient:
[server]
http = "127.0.0.1:8080"
document_root = "/srv/site"
serve_only = "static"
Use --front-controller '' so requests for paths that do not name a file return 404.
Without this flag, the default front controller (index.php) remains active. If that file
is unavailable to handle a request, Volucer returns 500. volucer check reports this
configuration issue at startup.
The rule
Static files are resolved under the same document root as scripts:
server.document_root.
If a request path resolves to a real file under the document root, Volucer serves it from
disk. Otherwise, it dispatches the request to the application. For example,
/assets/app.css may resolve to a file, while /about can continue to the front
controller.
A route can mount its own directory
A [[server.routes]] entry that states root serves its subtree from that directory
instead. The route's path_prefix is the mount point and is stripped before the path is
joined, so the directory replaces the document root rather than nesting inside it:
[[server.routes]]
path_prefix = "/downloads"
root = "/srv/files"
policy = "static"
/downloads/report.pdf is served from /srv/files/report.pdf, with the layer's ranges,
ETag, If-Range and precompressed-variant handling unchanged. This is the way to publish
a directory that is not under the document root without a symlink or an application script.
Two things a route root does not change:
- Script resolution. A
.php,.php3or.phtmlfile under a route root is never served from disk, exactly as under the document root — the guard is the site's list, so a mount cannot become a way to publish source. - The refusals.
..is refused before any filesystem access and dotfiles are hidden, by the same code that resolves the site's root.
The root is written as an absolute path, and a root that does not exist is a startup error
rather than a silently empty mount. It also requires a path_prefix: the prefix is the mount
point, so a root without one would have nowhere to be served from.
Two rules that always hold
These protections apply whether or not static serving is enabled:
- Non-script files are never executed as scripts. Only files with
.php,.php3, or.phtmlextensions can be executed. Other paths are passed to the front controller as application input. This preventsphp-cgifrom returning the contents of files it cannot parse, such as/config.jsonor/.env. - Dotfiles are never passed to the application, including as
PATH_INFO. Requests for dotfiles return 404 for every method.
What the layer serves
| Feature | Detail |
|---|---|
| Feature | Behavior |
| --- | --- |
| Content types | Uses a built-in table of common web content types; unknown types use application/octet-stream. |
| Validators | Sends ETag (based on length and modification time) and Last-Modified; supports 304 responses for If-None-Match and If-Modified-Since. |
| Ranges | Supports single and multiple byte ranges, including bytes=0-99, bytes=100-, and bytes=-500; returns 416 for ranges beyond the file and supports If-Range. |
| Precompressed files | Tries file.br, then file.gz, when requested by the client. This is opt-in and requires the file to exist. |
| Directory indexes | Serves index.html for directories and redirects /docs to /docs/ with a 301 response. |
| Caching | Applies one Cache-Control value to all served files. |
| Refusals | Returns 404 for dotfiles and 403 for paths containing a .. segment. |
| Scripts | Never serves .php, .php3, or .phtml files from disk, preventing source disclosure. |
Methods
The static layer handles GET, HEAD, and OPTIONS. Other methods, including POST,
are dispatched to the front controller even when the path names a file. This allows the
application to route those requests without exposing the file contents.
Precompressed files
[server.static_files]
precompressed = true
When the client accepts a supported encoding, serves app.js.br or app.js.gz if the
corresponding file exists.
Volucer does not generate compressed files. It serves the prebuilt file and sets the
appropriate Content-Encoding header. Generate these files as part of your build.
This option is disabled by default because it assumes your build produces the compressed files. A missing file is not an error; Volucer serves the original instead.
Cost
Serving a file does not use a PHP worker. Path resolution performs one stat, on the
runtime thread.
A slice of 256 KiB or less is read once with a single pread and sent as one already-in-memory
frame, which is the shape a small response wants: an exact Content-Length and no stream to
poll. Larger slices are streamed in 512 KiB blocks from a tokio file, with a Content-Length
frame, so the response is never chunked.
Both sizes were chosen by measurement, not by taste. Reading a small file through
tokio::fs::File costs a spawn_blocking per read — two thread wakeups and a Mutex handoff to
copy a few kilobytes — and removing that hop was worth 3.1x at 4,976 bytes. Streaming a large
one in 64 KiB blocks was worth 16 reads and 16 wakeups per MiB, and 512 KiB blocks were worth
3.6x at 1 MiB. 1 MiB blocks were measured too and are slightly slower.
Serving a small file therefore does not block a runtime thread for longer than a pread out of
the page cache. On a local filesystem that is microseconds. On a network filesystem a stat or
read is a round trip, so keep the document root local and serve remote files behind the
application instead.
Volucer does not use zero-copy sendfile; that would require a separate Unix-only code path, and
it is the one case where a competing server is faster: at 4,976 bytes a sendfile-based server
reaches about 111,000 responses a second against 243,000 here, while copy-based streaming is
faster than it from 100 KiB upward. File data is still copied as it is served.
Configuration
| Key | Type | Default | What it does |
|---|---|---|---|
enabled |
bool | true |
Serve files from the document root. |
precompressed |
bool | false |
Serve file.br or file.gz when the client accepts that encoding. |
directory_index |
bool | true |
Serve index.html for a directory. |
dotfiles |
string | "deny" |
Set to "deny" or "allow" to control dotfile access. |
cache_control |
string | "public, max-age=3600" |
Set the Cache-Control response header for served files. |
max_multirange_bytes |
integer | 1048576 |
Limit the total size requested by a multi-range request. |
With dotfiles = "deny", requests return 404 rather than 403, so the response does not
reveal whether a dotfile exists.
Use dotfiles = "allow" only when the document root contains published assets and no
sensitive dotfiles.
The table specifies overrides to the current settings. Omitting enabled does not
automatically enable or disable static serving; it leaves the inherited value unchanged.
For example, this disables the static layer:
[server.static_files]
enabled = false
This changes cache_control while leaving enabled unchanged:
[server.static_files]
cache_control = "public, max-age=60"
Site settings are inherited per key. A site that sets precompressed = true, for
example, continues to inherit the server's cache_control.
Compression is a separate thing
Static-file compression and response compression are separate mechanisms:
| What | Compressed by | Cost per request |
|---|---|---|
| Static files | Your build, producing .br or .gz files beside the originals |
No compression work per request |
| Backend responses | Volucer, when enabled | CPU on the request path |
Backend response bodies are generated for each request, so they cannot be precompressed
in the build. Configure runtime response compression with [server.compression]:
[server.compression]
enabled = true
encodings = ["gzip", "zstd"] # the default; order decides ties
level = 6 # gzip 1-9, zstd 1-19, clamped per encoding
min_length = 1024 # bodies below this are passed through
Runtime compression is disabled by default. It uses CPU while handling a request, so enable it when the reduction in response size is worth that cost for your workload.
Gzip is listed first because it is widely supported. Zstandard is also available and can produce smaller text responses; its window is limited to 8 MiB, the largest size accepted by current browsers.
Brotli is not offered for runtime compression. Its reference implementation defaults to
quality 11, which is more appropriate for build-time processing. Generate Brotli
.br files ahead of time and serve them with the static-file layer instead.
What is never compressed
These responses are not compressed, regardless of configuration:
- Bodies smaller than
min_length, or bodies that would become larger after compression. - Responses that already have
Content-EncodingorContent-Range. A range response is a portion of another representation. - Content that is already compressed or encoded: images other than SVG and icons, video,
audio, fonts, ZIP/GZIP/Zstandard archives, PDF, WebAssembly, and
application/grpc, which negotiates its own encoding.
Compressed responses include Vary: accept-encoding, appended to any existing Vary
value. This prevents caches from serving a compressed response to a client that does not
accept that encoding. If a client sets q=0 for both supported encodings, Volucer sends
the uncompressed response rather than returning 406.
A site can override these settings. If it specifies an encodings list, that list
replaces the server-level list rather than adding to it:
[sites.api.compression]
enabled = true
encodings = ["zstd"]