Static files

The static HTTP middleware serves static content using RoadRunner on the main HTTP plugin endpoint. Using this middleware can slow down the overall performance by up to ~10%, because RoadRunner has to check the path for each file request.

If there is no file to serve, RR will redirect the request back to the PHP worker.

Enable HTTP middleware

To enable static content serving, use the configuration inside the HTTP section:

.rr.yaml
version: "3"

http:
  # host and port separated by semicolon
  address: 127.0.0.1:44933
  middleware: [ "static" ] # Add static to the list of middleware
  static:
    dir: "."
    forbid: [ "" ]
    calculate_etag: false
    weak: false
    allow: [ ".txt", ".php" ]
    request:
      input: "custom-header"
    response:
      output: "output-header"

Where:

  1. dir: path to the directory.

  2. forbid: file extensions that should not be served.

  3. allow: extensions that should be served (empty = serve all except forbidden). If an extension is present in both lists (allow and forbid), it is treated as forbidden.

  4. calculate_etag: enable etag calculation for the static file.

  5. weak: use a weak generator (/W); it uses only the filename to generate a CRC32 sum. If false, the entire file content is used to generate the CRC32 sum.

  6. request/response: custom headers for the static files.

To combine static content with other middleware, use the following sequence (static last, then headers and gzip):

Fileserver plugin

The Fileserver plugin serves static files. It works similarly to the static HTTP middleware and has extended functionality. Static HTTP middleware slows down request processing by ~10% because RR has to check each request for the corresponding file. The file server plugin uses a different port and serves only static files.

File server configuration

Last updated

Was this helpful?