Configuration generation
Configuration generation turns shared settings, service values, and plugin configuration into the NGINX files used by the gateway. It validates the input, renders the matching configuration templates, installs a complete file tree, and publishes that tree to gateway instances before reload. It is the configuration boundary for the runtime security engine and supplies the settings used by request security processing.
Configuration sources
The configuration model combines a shared setting catalog with plugin-defined settings. Each setting has a scope, default value, input rule, and value type. Global settings control the gateway as a whole, while multisite settings can be set for an individual service. Core, external, and Pro plugins extend the same model, so their settings can drive both gateway behavior and generated NGINX directives (src/…/settings.json• L1-80, src/…/Configurator.py• L43-50).
The configuration helper builds one effective configuration from defaults, an optional database template, and accepted environment values. In multisite mode it also maps service names to service-scoped settings. Database services supplement the service list when startup values are not yet current, but draft services are excluded. Unknown or invalid values do not become NGINX input, and unknown values are redacted in logs so configuration warnings do not expose secrets (src/…/Configurator.py• L261-287, src/…/Configurator.py• L289-369).
Template composition
The template system is the bridge between the effective configuration and NGINX syntax. It searches shared templates together with the confs areas of enabled plugins, then selects templates by NGINX context such as global, HTTP, stream, default server, or service server (src/…/Templator.py• L551-597).
Global templates establish the NGINX process, HTTP, stream, and default-server structure. Service templates add the server-specific behavior for each configured service. In multisite mode, the renderer separates global values from service values and writes each service under its own output path, so one service can use a different setting without changing the shared gateway structure (src/…/Templator.py• L363-424, src/…/Templator.py• L647-667, src/…/Templator.py• L734-789).
Templates can use shared configuration, complete configuration, and default values to decide which gateway features to emit. The renderer also adapts selected values to NGINX syntax and checks automatic TLS curve selection against the capabilities available in the runtime. This keeps generated files usable across supported TLS environments without changing the service setting contract (src/…/Templator.py• L145-161, src/…/Templator.py• L517-549, src/…/Templator.py• L775-783).
The generated structure is assembled through NGINX includes. The main configuration loads shared HTTP and stream files, plugin output, and supported custom configuration files. A service server block then loads service-specific generated files and custom files (/home/user/repo/src/common/confs/nginx.conf#L67-L87, /home/user/repo/src/common/confs/http.conf#L101-L127, /home/user/repo/src/common/confs/server-http/server.conf#L39-L56).
Generation and publication flow
The generation flow keeps the active configuration in place until a complete new tree is ready. The scheduler generates the tree, sends it to each registered gateway at /confs, and asks the gateway to validate and reload it (home/…/main.py• L115-186, home/…/main.py• L1582-1622).
flowchart LR
A[Shared settings and plugin metadata] --> B[Configuration helper]
C[Database values and environment values] --> B
B --> D[Effective configuration]
D --> E[Template renderer]
E --> F[Staged NGINX file tree]
F --> G[Atomic installation]
G --> H[Gateway /confs upload]
H --> I[Configuration test and NGINX reload]
The installer swaps files into place without first emptying the destination. It uses a generation lock and a reload marker to avoid exposing NGINX to a mixture of old and new files. If rendering or installation cannot complete safely, the current configuration remains in use (home/…/sync_tree.py• L58-70, home/…/sync_tree.py• L179-203).
The renderer writes a stable environment file as part of the generated tree and renders global files before service files. Some global fragments are rendered after service staging when they need service-generated data. A large multisite deployment can therefore render services in parallel while still preserving the required ordering between shared and service output (src/…/Templator.py• L446-490, src/…/Templator.py• L628-645, src/…/Templator.py• L698-721).
Runtime loading
The gateway consumes the published file tree through the NGINX include layout. NGINX loads the shared process settings first, then HTTP and stream files, then service files selected by the generated configuration. This lets the runtime apply settings as native NGINX directives while Lua and security modules use the same generated values (/home/user/repo/src/common/confs/nginx.conf#L27-L87, /home/user/repo/src/common/confs/http.conf#L56-L86).
Reload is a controlled handoff from the published tree to NGINX workers. The API can validate configuration without applying it, or request a reload after the scheduler has sent the generated files. A failed generation or failed delivery prevents a reload from being treated as a successful application of the new settings (home/…/instances.py• L28-37, home/…/main.py• L1592-1624).
Change checklist
When these files or sections are changed, remember to consider these:
- Keep setting scope, service-prefix rules, and multiline file-value handling aligned between settings.json, plugin metadata,
Configurator, and service templates. - Keep template context names aligned with the NGINX include paths. A context mismatch can silently omit a feature from the generated tree.
- Keep template defaults and helper behavior aligned with the setting values that templates expect. This includes NGINX value normalization and automatic TLS curve selection.
- Keep the generated file layout aligned with the include paths in
nginx.conf,http.conf, and the service server templates. - Preserve the generate, upload, and reload order when changing scheduler publication behavior. A reload before
/confsreaches an instance can activate an older file tree. - Preserve the install guard when changing output writes. NGINX must not read files from two configuration generations during a reload.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A setting or plugin value fails its declared input rule | The value is rejected and is not used for generation | Configurator validates setting names, scope, types, newlines, and regular expressions before returning the effective configuration |
| A multiline file setting is parsed as separate environment values | A certificate or other file-backed setting reaches generation incomplete | The environment parser uses the setting catalog to preserve values whose type is file |
| A draft or unknown multisite service enters the service list | The generator can create an unintended or incomplete server block | Database service discovery excludes drafts, and service names and service-scoped values are validated before expansion |
| A template fails to render | The new tree is not installed, so the gateway keeps its current configuration | The generator reports failed global or service renders and stops the replacement flow |
| The runtime does not support a requested automatic TLS curve | NGINX can receive a curve list that the active TLS library cannot use | The renderer probes supported groups and falls back to a compatible curve set |
| Generation and reload overlap | NGINX could read a mix of routing files and variables from different generations | The install guard coordinates the generator lock with the reload marker |
| Generated files are not delivered to an instance | The instance still has the prior configuration | The scheduler only treats the reload stage as successful after file publication and reload responses are checked |
Key files
| File | Why to read it |
|---|---|
| src/…/settings.json | Defines the shared setting contract, scope, defaults, and input rules. |
| src/…/Configurator.py | Explains how defaults, templates, database values, and environment values become one effective configuration. |
| src/…/Templator.py | Explains how shared and plugin templates become global and service-specific NGINX files. |
| src/…/main.py | Shows the top-level generation and safe installation flow. |
| src/…/sync_tree.py | Shows how publication avoids partial file trees during reload. |
src/common/confs/nginx.conf | Shows how the runtime loads generated HTTP, stream, and custom configuration. |
src/common/confs/http.conf | Shows the shared HTTP runtime boundary and service include selection. |
src/common/confs/server-http/server.conf | Shows how one generated service server loads its feature and custom configuration. |
| src/…/main.py | Shows how generated files reach instances and how reload follows publication. |
| src/…/instances.py | Shows the runtime reload interface used by the scheduler and management API. |