It is possible to serve static content using RoadRunner. Important note: if there is no such file to serve, RR will redirect the request back to the PHP worker.
To enable static content serving use the configuration inside the http section:
version: "2.7"
http:
# host and port separated by semicolon
address: 127.0.0.1:44933
middleware: [ "static" ]
# Settings for "static" middleware (docs: https://roadrunner.dev/docs/middleware-static/2.x/en).
static:
dir: "."
forbid: [ "" ]
calculate_etag: false
weak: false
allow: [ ".txt", ".php" ]
request:
input: "custom-header"
response:
output: "output-header"
Where:
dir
: path to the directory.forbid
: file extensions that should not be served.allow
: file extensions which should be served (empty - serve all except forbidden). If extension presented in both (allow and forbid) hashmaps - that treated as we should forbid file extension.calculate_etag
: turn on etag computation for the static file.weak
: use a weak generator (/W), it uses only filename to generate a CRC32 sum. If false - all file content used to generate CRC32 sum.request/response
: custom headers for the static files.To combine static content with other middleware, use the following sequence (static will always be the last in the row, file server will apply headers and gzip plugins):
version: "2.7"
http:
# host and port separated by semicolon
address: 127.0.0.1:44933
middleware: [ "static", headers", "gzip" ]
# Settings for "headers" middleware (docs: https://roadrunner.dev/docs/http-headers).
headers:
cors:
allowed_origin: "*"
allowed_headers: "*"
allowed_methods: "GET,POST,PUT,DELETE"
allow_credentials: true
exposed_headers: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
max_age: 600
# Settings for "static" middleware (docs: https://roadrunner.dev/docs/middleware-headers/2.x/en).
static:
dir: "."
forbid: [ "" ]
calculate_etag: false
weak: false
allow: [ ".txt", ".php" ]
request:
input: "custom-header"
response:
output: "output-header"