Skip to content

Configuration

API Gateway uses YAML configuration files. This document describes all available configuration options.

Configuration File Structure

yaml
version: v1              # Configuration version
port: 8080               # Gateway listening port
baseuri: /v1             # Base URI prefix (optional)

cache:                   # Cache configuration (optional)
  engine: redis
  host: 127.0.0.1
  port: 6379
  password: ""
  db: 0
  prefix: "gozoox-api-gateway:"

healthcheck:             # Health check configuration
  outer:                 # External health check
    enable: true
    path: /healthz
    ok: true
  inner:                 # Internal service health check
    enable: true
    interval: 30         # Check interval in seconds
    timeout: 5           # Timeout in seconds

backend:                 # Default backend (optional)
  service:
    protocol: https
    name: example.com
    port: 443

routes:                  # Route definitions
  - name: route-name
    path: /api
    path_type: prefix    # prefix or regex
    backend:
      service:
        protocol: https
        name: backend.example.com
        port: 443
        request:
          path:
            disable_prefix_rewrite: false
            rewrites:
              - "^/api/(.*):/$1"
          headers:
            X-Custom-Header: value
          query:
            key: value
        response:
          headers:
            X-Response-Header: value
        auth:
          type: bearer
          token: your-token

Configuration Fields

Top Level

FieldTypeRequiredDefaultDescription
versionstringYes-Configuration version (currently v1)
portintNo8080Port the gateway listens on
baseuristringNo-Base URI prefix for all routes
cacheobjectNo-Cache configuration
healthcheckobjectNo-Health check configuration
backendobjectNo-Default backend service
routesarrayNo[]Route definitions

Cache Configuration

FieldTypeRequiredDefaultDescription
enginestringNoredisCache engine (currently only redis)
hoststringNo127.0.0.1Redis host
portintNo6379Redis port
passwordstringNo-Redis password
dbintNo0Redis database number
prefixstringNogozoox-api-gateway:Key prefix

Health Check Configuration

Outer Health Check

FieldTypeRequiredDefaultDescription
enableboolNofalseEnable external health check endpoint
pathstringNo/healthzHealth check endpoint path
okboolNotrueAlways return OK (skip actual checks)

Inner Health Check

FieldTypeRequiredDefaultDescription
enableboolNofalseEnable internal service health checks
intervalintNo30Check interval in seconds
timeoutintNo5Request timeout in seconds

Service Health Check

FieldTypeRequiredDefaultDescription
enableboolNofalseEnable health check for this service
methodstringNoGETHTTP method for health check
pathstringNo/healthHealth check endpoint path
statusarrayNo[200]Valid HTTP status codes
intervalintNo30Check interval in seconds
timeoutintNo5Request timeout in seconds
okboolNofalseAlways consider healthy (skip checks)

Route Configuration

FieldTypeRequiredDefaultDescription
namestringYes-Route name (for logging)
pathstringYes-Path pattern to match
path_typestringNoprefixMatch type: prefix or regex
backendobjectYes-Backend service configuration

Service Configuration

FieldTypeRequiredDefaultDescription
protocolstringNohttpProtocol: http or https
namestringNo*-Service hostname or IP (required for single-server mode)
portintNo*80Service port (required for single-server mode)
algorithmstringNoround-robinLoad balancing algorithm: round-robin, weighted, least-connections, ip-hash
serversarrayNo[]Server instances for load balancing (if set, enables multi-server mode)
requestobjectNo-Request transformation
responseobjectNo-Response transformation
authobjectNo-Authentication configuration
health_checkobjectNo-Service-specific health check

Note: For single-server mode, name and port are required. For multi-server mode, servers array is required.

Server Configuration (for multi-server mode)

FieldTypeRequiredDefaultDescription
namestringYes-Server hostname or IP
portintYes-Server port
protocolstringNo-Protocol (inherits from service if not set)
weightintNo1Weight for weighted algorithm
disabledboolNofalseDisable server (server is enabled by default)
requestobjectNo-Server-specific request configuration (overrides global)
responseobjectNo-Server-specific response configuration (overrides global)
authobjectNo-Server-specific authentication (overrides global)
health_checkobjectNo-Server-specific health check (overrides global)

Request Configuration

FieldTypeRequiredDefaultDescription
pathobjectNo-Path rewriting configuration
headersmapNo-Additional request headers
querymapNo-Additional query parameters

Path Rewriting

FieldTypeRequiredDefaultDescription
disable_prefix_rewriteboolNofalseDisable automatic prefix removal
rewritesarrayNo[]Path rewrite rules (format: pattern:replacement)

Response Configuration

FieldTypeRequiredDefaultDescription
headersmapNo-Additional response headers

Authentication Configuration

FieldTypeRequiredDefaultDescription
typestringNo-Auth type: basic, bearer, jwt, oauth2, oidc
usernamestringNo-Username (for basic auth)
passwordstringNo-Password (for basic auth)
tokenstringNo-Bearer token
secretstringNo-JWT secret
providerstringNo-OAuth2 provider
client_idstringNo-OAuth2 client ID
client_secretstringNo-OAuth2 client secret
redirect_urlstringNo-OAuth2 redirect URL
scopesarrayNo[]OAuth2 scopes

Path Rewrite Rules

Path rewrite rules use the format pattern:replacement:

  • ^/api/(.*):/$1 - Remove /api prefix
  • ^/v1/user/(.*):/user/$1 - Transform path
  • ^/old/(.*):/new/$1 - Replace path segment

Patterns use regular expressions. The replacement can reference capture groups.

Examples

See Examples for complete configuration examples.

Load Balancing

For load balancing configuration, see Load Balancing guide.

Next Steps

Released under the MIT License.