Serve static files
Serve a directory of static files (HTML, CSS, JS, images) over HTTP — with compression, no application server required.
Configuration
Section titled “Configuration”Put the files in a directory and point a site at it with file_server:
static.example.com { root /var/www/html file_server}root sets the directory; file_server serves it. A relative path like
./public is resolved from raddex’s working directory.
To send compressed responses, add encode — the first algorithm the client also
supports wins. gzip, zstd, and Brotli (br) are available:
static.example.com { root /var/www/html file_server encode br zstd gzip}See the Compression guide for how negotiation works and how to choose algorithms.
Run it
Section titled “Run it”raddex check -c Raddexfileraddex run -c RaddexfileWhat you get
Section titled “What you get”curl -H 'Host: static.example.com' http://127.0.0.1:8090/ # index.htmlcurl -H 'Host: static.example.com' http://127.0.0.1:8090/app.js # a filecurl -H 'Host: static.example.com' -H 'Accept-Encoding: gzip' \ http://127.0.0.1:8090/app.js -sD - -o /dev/null # Content-Encoding: gzipBehavior to rely on:
- A directory serves its
index.html—/maps toindex.html. - Only
GETandHEADare allowed; other methods are rejected. - Path traversal is blocked —
/../etc/passwdreturns404, not your files. encodecompressesfile_serverresponses too, honoring the client’sAccept-Encoding.file_serverservesroot+ the full request path, including anyhandleprefix (see below).
Serving a subpath
Section titled “Serving a subpath”Use handle to serve static files under one path while proxying everything
else:
example.com { handle /static/* { root /var/www/html file_server encode zstd gzip }
reverse_proxy 127.0.0.1:8080}Here /static/app.js maps to /var/www/html/static/app.js — the handle
prefix is kept in the path.