Chapter 3 — Sites and Routing

Last Updated: 2026-12-04 09:44 Views: 12

3.1 Site model

One site maps to one servers node stored in conf/vhost/{name}.toml. include = ["vhost/*.toml"] in http aggregates them; the console splits files by site on save. A name may contain only letters, digits, ., - and _; empty means derive it from the domain.

Key Purpose
name Manager/converter only: picks conf/vhost/{name}.toml; not stored in the site file
domain Domain array; * marks the catch-all site
listen Listen address, TLS, HTTP/2, HTTP/3
root / index Root and default index, ["index.html"]
locations Inline array; regexes match in array order
ssl Store name or certificate/key paths
error_page Status code to URI or file mapping
access_log / waf Override global log; site WAF switch and rules

The vhost file name is the site name: a name written inside the site file is ignored and never written back; one file may contain multiple sites (same-name sites are saved to the same file). Manager’s name only selects the save file; empty derives it from the domain.

3.2 Domains and listeners

Matching order: exact domain → *.example.com / example.* wildcards (site-file order) → domain = ["*"] catch-all → first site. Sites may share one addr; TLS picks a certificate by SNI, HTTP routes by Host.

listen accepts ":80", "8080", "1.2.3.4:8080" and "[::]:443". Common forms:

listen = [{ addr = ":80" }]
listen = [{ addr = ":443", ssl = true, http2 = true, http3 = true }]

http3 = true also requires ssl = true; the server then listens on UDP on the same port and advertises Alt-Svc: h3=":port"; ma=86400.

3.3 Location matching

Form Type
= /exact Exact match, highest priority
/prefix/ Prefix match
^~ /static/ Prefix match that skips regexes once hit
~ \.php$ Regex, case-sensitive
~* \.jpg$ Regex, case-insensitive

Priority is exact → longest prefix (^~ stops regex evaluation) → regexes in order → longest prefix. Regex locations and wildcard domains follow configuration order; don’t reorder casually.

3.4 Content handlers

location.type selects the module that handles the request:

type Description
static Root/alias/index/autoindex/try_files/WebDAV
proxy Load balancing, retries, WebSocket, cache, slicing
fastcgi PHP/FastCGI with split_path_info and connection reuse
uwsgi / scgi uwsgi / SCGI protocol backends
grpc gRPC passthrough over HTTP/2 h2c or TLS
memcached memcached source; a miss returns 404
return / redirect Status code, text or redirect
image / mp4 Thumbnails with watermarks; MP4 pseudo-streaming
empty_gif / stub_status 1x1 transparent GIF; status page

3.5 Error pages and site overrides

error_page supports three target forms (allowed at http / site / location level; inheritance is location > site > http):

Form Example Behavior
file: file:4xx.html, file:/var/wxserver/html/4xx.html Relative paths resolve under error_page_root (default: the built-in pages directory /var/wxserver/html or <exe>/../html); absolute paths are used as-is; the file is read and rendered
root: root:errors/404.html Resolves under the site root; read and rendered
link: link:/404.html, link:@fallback, link:https://example.com/404 Internal redirect (302 for a full URL); no rendering

Without configuration the defaults are 4xx → file:4xx.html and 5xx → file:5xx.html (generated errors always; upstream errors need *_intercept_errors). Files are capped at 1 MB and rendered with html/template, variables escaped automatically. -t and Manager saves validate target syntax (unknown prefixes, .., control characters error out). Legacy forms (/uri, relative paths, @name, http(s)://) remain supported.

A site can turn off its access log (access_log = { enabled = false }) or WAF (waf = { enabled = false }), and override client_max_body_size, limit_rate and similar per location.

3.6 Minimal example

http = {
  servers = [
    {
      domain = ["example.com", "www.example.com"],
      listen = [{ addr = ":443", ssl = true, http2 = true }],
      ssl = { cert = "example.com" },
      root = "html",
      index = ["index.html"],
      error_page = { "404" = "file:4xx.html", "5xx" = "file:5xx.html" },
      waf = { enabled = true },
      locations = [
        { path = "/", type = "static" },
        { path = "/api/", type = "proxy", proxy_pass = "http://backend" },
      ],
    },
  ],
}

3.7 Site-level protocol and module overrides

HTTP/2 and HTTP/3 are enabled on the listen entry itself (ssl = true, http2 = true / http3 = true); modules can be disabled per site with disabled_modules = ["http_zstd"]. Site-level http2 = false / http3 = false are legacy hard-off switches; a global http2/http3 = false cannot be overridden by a site.

sendfile can also be overridden at site/location level; see Chapter 9.

← Previous Article Chapter 2 — Web Console Next Article → Chapter 4 — TLS and Certificates

Comments

No comments yet