Menu

Environment Variable Overrides

Relevant source files

Nginx UI configuration settings defined in app.ini can be overridden using environment variables. This enables containerized deployments and CI/CD environments to configure the application without modifying configuration files.

For the base configuration file structure, see page 9.1.

Overview

The environment variable override system uses the NGINX_UI_ prefix followed by section and field names. Environment variables are parsed during application initialization and take precedence over file-based configuration. The implementation uses the github.com/caarlos0/env/v11 library for type-safe parsing.

Sources: settings/settings.go72-99 settings/settings.go114-123

Naming Convention

Environment variable names follow the pattern:

NGINX_UI_<SECTION>_<FIELD_NAME> 

Where:

  • NGINX_UI_ is the constant prefix defined in settings/settings.go18
  • <SECTION> is the INI section name in uppercase
  • <FIELD_NAME> is the struct field name converted to uppercase with underscores

Naming Examples

INI SectionINI KeyGo Struct FieldEnvironment Variable
[app]PageSizeAppSettings.PageSizeNGINX_UI_APP_PAGE_SIZE
[server]HostServerSettings.HostNGINX_UI_SERVER_HOST
[nginx]ConfigDirNginxSettings.ConfigDirNGINX_UI_NGINX_CONFIG_DIR
[cert]HTTPChallengePortCertSettings.HTTPChallengePortNGINX_UI_CERT_HTTP_CHALLENGE_PORT

Sources: settings/settings.go18 settings/settings.go23-43

Processing Flow

Title: Environment Variable Processing During Application Initialization

Sources: settings/settings.go72-99

Implementation

envPrefixMap Structure

The envPrefixMap at settings/settings.go23-43 maps environment variable prefixes to Go struct pointers. Each entry associates a section prefix with the corresponding settings struct that will receive parsed values.

Title: envPrefixMap Section-to-Struct Mapping

Sources: settings/settings.go23-43

parseEnv Function

The parseEnv function at settings/settings.go114-123 performs type-safe environment variable parsing:

Parsing Behavior:

  • Prefix Construction: Concatenates EnvPrefix (NGINX_UI_) with section prefix (e.g., SERVER_ → NGINX_UI_SERVER_)
  • Field Matching: Uses struct field names directly (no tag required)
  • Type Conversion: Handles int, uint, string, bool, []string automatically
  • Array Parsing: Splits comma-separated values into string slices
  • Error Handling: Application terminates with fatal error if parsing fails

Sources: settings/settings.go114-123 settings/settings.go18

Complete Environment Variable Reference

App Section

Configuration FieldEnvironment VariableTypeDefaultDescription
PageSizeNGINX_UI_APP_PAGE_SIZEint20Number of items per page in UI
JwtSecretNGINX_UI_APP_JWT_SECRETstring(empty)JWT signing secret

Sources: app.example.ini1-3 docs/guide/env.md5-9

Server Section

Configuration FieldEnvironment VariableTypeDefaultDescription
HostNGINX_UI_SERVER_HOSTstring0.0.0.0Server bind address
PortNGINX_UI_SERVER_PORTuint9000Server listen port
RunModeNGINX_UI_SERVER_RUN_MODEstringdebugRun mode: debug/release
EnableHTTPSNGINX_UI_SERVER_ENABLE_HTTPSboolfalseEnable HTTPS
EnableH2NGINX_UI_SERVER_ENABLE_H2boolfalseEnable HTTP/2
EnableH3NGINX_UI_SERVER_ENABLE_H3boolfalseEnable HTTP/3

Sources: app.example.ini5-11 docs/guide/env.md12-20

Database Section

Configuration FieldEnvironment VariableTypeDefaultDescription
NameNGINX_UI_DB_NAMEstringdatabaseSQLite database filename

Sources: app.example.ini14-15 docs/guide/env.md22-25

Auth Section

Configuration FieldEnvironment VariableTypeDefaultDescription
IPWhiteListNGINX_UI_AUTH_IP_WHITE_LIST[]string(empty)Whitelisted IP addresses (comma-separated)
BanThresholdMinutesNGINX_UI_AUTH_BAN_THRESHOLD_MINUTESint10Minutes before banned IPs expire
MaxAttemptsNGINX_UI_AUTH_MAX_ATTEMPTSint10Max failed login attempts before ban

Sources: app.example.ini17-20 docs/guide/env.md27-32

Casdoor Section

Configuration FieldEnvironment VariableTypeDefaultDescription
EndpointNGINX_UI_CASDOOR_ENDPOINTstring(empty)Casdoor server endpoint
ClientIdNGINX_UI_CASDOOR_CLIENT_IDstring(empty)OAuth client ID
ClientSecretNGINX_UI_CASDOOR_CLIENT_SECRETstring(empty)OAuth client secret
CertificatePathNGINX_UI_CASDOOR_CERTIFICATE_PATHstring(empty)Certificate file path
OrganizationNGINX_UI_CASDOOR_ORGANIZATIONstring(empty)Casdoor organization name
ApplicationNGINX_UI_CASDOOR_APPLICATIONstring(empty)Casdoor application name
RedirectUriNGINX_UI_CASDOOR_REDIRECT_URIstring(empty)OAuth redirect URI

Sources: app.example.ini22-29 docs/guide/env.md34-43

Cert Section

Configuration FieldEnvironment VariableTypeDefaultDescription
EmailNGINX_UI_CERT_EMAILstring(empty)ACME account email
CADirNGINX_UI_CERT_CA_DIRstring(empty)Certificate authority directory
RenewalIntervalNGINX_UI_CERT_RENEWAL_INTERVALint7Days before expiry to renew
RecursiveNameserversNGINX_UI_CERT_RECURSIVE_NAMESERVERS[]string(empty)DNS servers for DNS-01 challenge
HTTPChallengePortNGINX_UI_CERT_HTTP_CHALLENGE_PORTstring9180Port for HTTP-01 challenge

Sources: app.example.ini31-36 docs/guide/env.md45-52

Cluster Section

Configuration FieldEnvironment VariableTypeDefaultDescription
NodeNGINX_UI_CLUSTER_NODE[]string(empty)Cluster node URLs (comma-separated)

Example: NGINX_UI_CLUSTER_NODE="http://10.0.0.1:9000?name=node1&node_secret=secret&enabled=true,http://10.0.0.2:9000?name=node2&node_secret=secret&enabled=true"

Sources: app.example.ini38-41 docs/guide/env.md54-57

Crypto Section

Configuration FieldEnvironment VariableTypeDefaultDescription
SecretNGINX_UI_CRYPTO_SECRETstring(empty)Encryption secret for sensitive data

Sources: app.example.ini43-44 docs/guide/env.md59-62

HTTP Section

Configuration FieldEnvironment VariableTypeDefaultDescription
GithubProxyNGINX_UI_HTTP_GITHUB_PROXYstringhttps://mirror.ghproxy.com/GitHub proxy URL
InsecureSkipVerifyNGINX_UI_HTTP_INSECURE_SKIP_VERIFYboolfalseSkip TLS certificate verification

Sources: app.example.ini46-48 docs/guide/env.md64-68

Logrotate Section

Configuration FieldEnvironment VariableTypeDefaultDescription
EnabledNGINX_UI_LOGROTATE_ENABLEDboolfalseEnable automatic log rotation
CMDNGINX_UI_LOGROTATE_CMDstringlogrotate /etc/logrotate.d/nginxLog rotation command
IntervalNGINX_UI_LOGROTATE_INTERVALint1440Rotation interval in minutes

Sources: app.example.ini50-53 docs/guide/env.md70-75

Nginx Section

Configuration FieldEnvironment VariableTypeDefaultDescription
AccessLogPathNGINX_UI_NGINX_ACCESS_LOG_PATHstring/var/log/nginx/access.logDefault access log path
ErrorLogPathNGINX_UI_NGINX_ERROR_LOG_PATHstring/var/log/nginx/error.logDefault error log path
ConfigDirNGINX_UI_NGINX_CONFIG_DIRstring(auto-detected)Nginx configuration directory
PIDPathNGINX_UI_NGINX_PID_PATHstring(auto-detected)Nginx PID file path
SbinPathNGINX_UI_NGINX_SBIN_PATHstring(auto-detected)Nginx binary path
TestConfigCmdNGINX_UI_NGINX_TEST_CONFIG_CMDstring(auto-detected)Command to test config
ReloadCmdNGINX_UI_NGINX_RELOAD_CMDstringnginx -s reloadCommand to reload Nginx
RestartCmdNGINX_UI_NGINX_RESTART_CMDstring(varies)Command to restart Nginx
LogDirWhiteListNGINX_UI_NGINX_LOG_DIR_WHITE_LIST[]string/var/log/nginxAllowed log directories
StubStatusPortNGINX_UI_NGINX_STUB_STATUS_PORTint0Port for stub_status module
ContainerNameNGINX_UI_NGINX_CONTAINER_NAMEstring(empty)Docker container name

Sources: app.example.ini55-63 docs/guide/env.md77-90

Nginx Log Section

Configuration FieldEnvironment VariableTypeDefaultDescription
IndexingEnabledNGINX_UI_NGINX_LOG_INDEXING_ENABLEDboolfalseEnable advanced log indexing
IndexPathNGINX_UI_NGINX_LOG_INDEX_PATHstring(empty)Bleve index storage path

Sources: app.example.ini65-67 docs/guide/env.md92-96

Node Section

Configuration FieldEnvironment VariableTypeDefaultDescription
NameNGINX_UI_NODE_NAMEstringLocalDisplay name for this node
SecretNGINX_UI_NODE_SECRETstring(empty)Node authentication secret
SkipInstallationNGINX_UI_NODE_SKIP_INSTALLATIONboolfalseSkip initial setup wizard
DemoNGINX_UI_NODE_DEMOboolfalseEnable demo mode

Sources: app.example.ini69-73 docs/guide/env.md98-103

OpenAI Section

Configuration FieldEnvironment VariableTypeDefaultDescription
ModelNGINX_UI_OPENAI_MODELstringgpt-4oAI model name
BaseUrlNGINX_UI_OPENAI_BASE_URLstring(empty)API base URL
ProxyNGINX_UI_OPENAI_PROXYstring(empty)HTTP proxy for API requests
TokenNGINX_UI_OPENAI_TOKENstring(empty)API authentication token
APITypeNGINX_UI_OPENAI_API_TYPEstring(empty)API type identifier
EnableCodeCompletionNGINX_UI_OPENAI_ENABLE_CODE_COMPLETIONboolfalseEnable LLM code completion
CodeCompletionModelNGINX_UI_OPENAI_CODE_COMPLETION_MODELstringgpt-4o-miniModel for code completion

Sources: app.example.ini75-82 docs/guide/env.md105-111

Terminal Section

Configuration FieldEnvironment VariableTypeDefaultDescription
StartCmdNGINX_UI_TERMINAL_START_CMDstringbashCommand to start terminal session

Sources: app.example.ini84-85 docs/guide/env.md113-116

WebAuthn Section

Configuration FieldEnvironment VariableTypeDefaultDescription
RPDisplayNameNGINX_UI_WEBAUTHN_RP_DISPLAY_NAMEstringNginx UIRelying party display name
RPIDNGINX_UI_WEBAUTHN_RPIDstringlocalhostRelying party ID (domain)
RPOriginsNGINX_UI_WEBAUTHN_RP_ORIGINS[]string(multiple)Allowed origins for WebAuthn

Sources: app.example.ini87-90 docs/guide/env.md118-124

Special Cases and Array Handling

Array/Slice Values

Configuration fields that accept multiple values (slices in Go) use comma-separated values in environment variables:

The env library automatically splits comma-separated strings into Go slices.

Sources: settings/settings_test.go26-49 settings/settings.go114-123

Predefined User Creation

When NodeSettings.SkipInstallation is true, two additional environment variables enable automatic user creation without the setup wizard:

Environment VariablePurposeType
NGINX_UI_PREDEFINED_USER_NAMEUsername for initial userstring
NGINX_UI_PREDEFINED_USER_PASSWORDPassword for initial userstring

Sources: docs/guide/env.md126-131

Docker-Specific Override

When running in the official Docker container (detected via helper.InNginxUIOfficialDocker()), the system overrides NginxSettings.RestartCmd to "nginx -s stop" at settings/settings.go88-90 This is necessary because the s6-overlay supervisor automatically restarts Nginx when it exits, making stop equivalent to restart.

Title: Docker Environment Detection and Override

Sources: settings/settings.go88-90

Validation and Defaults

After environment variable parsing completes, the system applies validation rules and default values at settings/settings.go78-98:

ConditionActionLine
ServerSettings.Port == 0Set to 900078-80
AuthSettings.BanThresholdMinutes <= 0Set to 1092-94
AuthSettings.MaxAttempts <= 0Set to 1096-98

Sources: settings/settings.go78-98

Usage Examples

Docker Compose Example

Kubernetes ConfigMap Example

Sources: settings/settings_test.go10-93

Testing Environment Variable Override

The test suite at settings/settings_test.go10-178 demonstrates comprehensive environment variable override testing for all configuration sections. The test:

  1. Sets environment variables for all configuration sections
  2. Calls Init() to load configuration
  3. Asserts that environment variables override file-based configuration
  4. Validates array parsing for comma-separated values
  5. Confirms Docker-specific overrides

This test serves as both validation and documentation of the override system's behavior.

Sources: settings/settings_test.go10-178