Docs
/
Installation
/

Environment Variables

Environment Variables

Koios is configured through environment variables passed to the Docker container. Most deployments work with the defaults, but you can customize network ports, performance tuning, logging, authentication, and reverse proxy settings.

Setting Environment Variables

Add -e flags to the docker run command in your systemd service file:

ExecStart=/usr/bin/docker run --rm --name=%n --network host \
  -e ENABLE_TLS=true \
  -e HTTPS_PORT=8443 \
  -e LOG_STDOUT_ENABLED=true \
  --mount source=koios_data_postgres,target=/var/lib/postgresql/16/main \
  --mount source=koios_data_influxdb,target=/root/.influxdbv2 \
  --mount source=koios_media,target=/var/www/koios/media \
  --mount source=koios_logs,target=/var/www/koios/logs \
  --mount source=koios_certs,target=/var/www/koios/certs \
  --mount source=koios_license,target=/var/www/koios/license \
  --mount source=koios_secrets,target=/var/www/koios/secrets \
  aiopinc/koios:latest

After editing the service file, reload and restart:

sudo systemctl daemon-reload
sudo systemctl restart docker.koios.service

Network & TLS

Control how Koios handles HTTPS, HTTP, and port assignments.

VariableDefaultDescription
ENABLE_TLStrueWhen true, Koios serves HTTPS with a self-signed certificate and redirects HTTP to HTTPS. Set to false when running behind a load balancer or reverse proxy that handles TLS termination.
HTTPS_PORT443The port for HTTPS traffic. Only used when ENABLE_TLS=true.
HTTP_PORT80The port for HTTP traffic. In TLS mode, this port redirects to HTTPS. In no-TLS mode, this is the primary listening port.

Common Scenarios

Standard deployment (default): No variables needed — Koios listens on ports 443 (HTTPS) and 80 (HTTP redirect).

Custom ports:

-e HTTPS_PORT=8443 \
-e HTTP_PORT=8080 \

Behind a TLS-terminating proxy (e.g., NGINX, HAProxy, AWS ALB):

-e ENABLE_TLS=false \
-e HTTP_PORT=8080 \

Koios serves plain HTTP on port 8080. The proxy handles HTTPS and forwards traffic to this port.

Performance Tuning

Adjust worker threads and timeouts for your deployment size.

VariableDefaultDescription
UVICORN_WORKERSCPU count (max 4)Number of web server worker processes. Increase for deployments with many concurrent API clients.
GRAPHQL_REQUEST_TIMEOUT30Maximum time (in seconds) for a single API request to complete. Increase if large queries (e.g., bulk exports) are timing out.
DC_THREAD_POOL_SIZE8Number of worker threads for device polling. Increase for deployments with many devices to improve polling concurrency.
PE_THREAD_POOL_SIZE8Number of worker threads for AI model inference. Increase for deployments running many models concurrently.
PE_GROUP_THREAD_POOL_SIZE32Maximum threads for parallel model inference within a scan group. When a scan group fires, all its models can run concurrently up to this limit.
EE_THREAD_POOL_SIZE8Number of worker threads for expression evaluation. Increase for deployments with many calculated tags (expressions).
EE_IN_MEMORY_HEARTBEAT_INTERVAL60Safety-net poll interval (in seconds) for in-memory tag sources feeding expression tags and AI models. The Expression Evaluator now reacts to live in-memory updates via push events; this heartbeat is purely a fallback to detect a stale producer. Lower it only if you suspect a producer is silently failing to publish. The legacy EE_IN_MEMORY_SCAN_RATE variable is still honored for backward compatibility.

Authentication

Control JWT token lifetimes for user sessions.

VariableDefaultDescription
KOIOS_ACCESS_TOKEN_LIFETIME_SECONDS3600How long an access token remains valid (in seconds). Default is 1 hour. Shorter values improve security; longer values reduce re-authentication frequency.
KOIOS_REFRESH_TOKEN_LIFETIME_DAYS7How long a refresh token remains valid (in days). This determines the maximum session duration before a user must log in again.

Logging

Control log output destination, format, and verbosity.

VariableDefaultDescription
LOG_STDOUT_ENABLEDfalseWhen true, streams all service logs to container stdout, making them visible via docker logs. When false, logs are written to files inside the container's log volume and viewable from the in-app log viewer.
KOIOS_DEFAULT_LOG_LEVELINFOLog verbosity for all Koios services. Options: DEBUG, INFO, WARNING, ERROR, CRITICAL.

Log Forwarding (OpenTelemetry)

Forward logs from Koios to an external observability platform using the built-in OpenTelemetry Collector.

VariableDefaultDescription
OTEL_COLLECTOR_ENABLEDfalseWhen true, starts the OpenTelemetry Collector inside the container.
OTEL_REMOTE_ENDPOINT(none)The remote OTLP HTTP endpoint URL (e.g., https://your-collector:4318). Required when the collector is enabled.
OTEL_REMOTE_AUTH_TOKEN(none)Bearer token for authenticating to the remote endpoint.

Example: Forwarding to Grafana Cloud

-e OTEL_COLLECTOR_ENABLED=true \
-e OTEL_REMOTE_ENDPOINT=https://otlp-gateway-prod-us-east-0.grafana.net/otlp \
-e OTEL_REMOTE_AUTH_TOKEN=your-grafana-cloud-token \

OPC-UA Configuration

VariableDefaultDescription
OPCUA_CERT_HOSTNAMESystem hostnameThe hostname embedded in the OPC-UA client's application URI and used when generating client certificates. Override this if the system hostname doesn't match what your OPC-UA servers expect for certificate validation.

Reverse Proxy Settings

When running behind a reverse proxy, you may need to configure CSRF protection and cookie settings so that the proxy's domain and protocol are trusted.

CSRF Protection

VariableDefaultDescription
DJANGO_CSRF_TRUSTED_ORIGINS(empty)Comma-separated list of trusted origins. Must be set when behind a proxy to match the browser's Origin header. Example: https://koios.example.com,https://other.example.com
DJANGO_CSRF_COOKIE_SECURETrueSet to False if serving over plain HTTP (e.g., behind a proxy on a private network).
DJANGO_CSRF_COOKIE_HTTPONLYFalseSet to True to prevent JavaScript from reading the CSRF cookie.
DJANGO_CSRF_COOKIE_DOMAIN(current domain)Set to .example.com for cross-subdomain CSRF cookie sharing.
DJANGO_CSRF_COOKIE_PATH/URL path for the CSRF cookie.
DJANGO_CSRF_COOKIE_SAMESITE(browser default)SameSite attribute: Lax, Strict, or None.

Session Cookies

VariableDefaultDescription
DJANGO_SESSION_COOKIE_SECURETrueSet to False if serving over plain HTTP.
DJANGO_SESSION_COOKIE_DOMAIN(current domain)Domain for the session cookie.
DJANGO_SESSION_COOKIE_PATH/URL path for the session cookie.
DJANGO_SESSION_COOKIE_SAMESITELaxSameSite attribute for the session cookie.

Proxy Headers

VariableDefaultDescription
DJANGO_USE_X_FORWARDED_HOSTTrueUse the X-Forwarded-Host header from the proxy to determine the request host.
DJANGO_USE_X_FORWARDED_PORTTrueUse the X-Forwarded-Port header from the proxy.
DJANGO_SECURE_PROXY_SSL_HEADERHTTP_X_FORWARDED_PROTO,httpsHeader and expected value (comma-separated) used to detect HTTPS behind a proxy.
DJANGO_SECURE_SSL_REDIRECTFalseWhen True, the application redirects all HTTP requests to HTTPS. Usually False when the proxy handles redirection.

Example: Behind NGINX with Custom Domain

-e ENABLE_TLS=false \
-e HTTP_PORT=8080 \
-e DJANGO_CSRF_TRUSTED_ORIGINS=https://koios.example.com \
-e DJANGO_CSRF_COOKIE_SECURE=True \
-e DJANGO_SESSION_COOKIE_SECURE=True \

Debugging

These variables are intended for troubleshooting and should not be enabled in normal operation.

VariableDefaultDescription
DJANGO_DEBUGFalseEnables verbose error pages with stack traces. Never enable in production — it exposes sensitive information.
KOIOS_DB_QUERY_LOG(disabled)Database query logging for the data collection and inference services. Set to summary for a periodic 60-second summary, or verbose for every individual query with timing. Useful for diagnosing slow queries.