Gate Configuration
Gate Configuration Guide
Section titled “Gate Configuration Guide”Complete guide to configuring the Gate API Gateway.
Table of Contents
Section titled “Table of Contents”- Quick Start
- Configuration Files
- Environment Variables
- Server Settings
- TLS/HTTPS Configuration
- Observability
- Server Configurations
- Advanced Topics
Quick Start
Section titled “Quick Start”1. Create Your Configuration
Section titled “1. Create Your Configuration”# Development (repository)cp configs/gate/gate.config.sample.yml configs/gate/gate.config.yml
# Production (user directory)mkdir -p ~/.config/gate/serverscp configs/gate/gate.config.sample.yml ~/.config/gate/gate.config.yml2. Edit Configuration
Section titled “2. Edit Configuration”# Open in your editorvim ~/.config/gate/gate.config.yml3. Start Gate
Section titled “3. Start Gate”# Developmentnx serve gate
# ProductiongateConfiguration Files
Section titled “Configuration Files”Main Configuration File
Section titled “Main Configuration File”Filename: gate.config.{yml|yaml|toml|json}
Locations (checked in order):
{repository}/configs/gate/gate.config.yml(development)~/.config/gate/gate.config.yml(user install)/etc/gate/gate.config.yml(system-wide)
Server Configuration Files
Section titled “Server Configuration Files”Directory: servers/**/*.{yml|yaml|toml|json}
Locations (all loaded):
{repository}/configs/gate/servers/**/*~/.config/gate/servers/**/*/etc/gate/servers/**/*
Note: Gate uses glob patterns to automatically discover all config files in these directories.
Environment Variables
Section titled “Environment Variables”All configuration options can be overridden using environment variables with the GATE_ prefix.
Syntax
Section titled “Syntax”- Prefix:
GATE_ - Nesting: Double underscore
__ - Example:
GATE_SERVER__HTTP_PORT=8080
Common Examples
Section titled “Common Examples”# Server configurationexport GATE_SERVER__HOST="127.0.0.1"export GATE_SERVER__HTTP_PORT=8080export GATE_SERVER__HTTPS_PORT=8443export GATE_SERVER__MAX_CONNECTIONS=5000export GATE_SERVER__WORKER_THREADS=4
# TLS/HTTPSexport GATE_TLS__ENABLED=trueexport GATE_TLS__AUTO_REDIRECT_HTTP=trueexport GATE_TLS__CERT_PATH="/etc/letsencrypt/live/example.com/fullchain.pem"export GATE_TLS__KEY_PATH="/etc/letsencrypt/live/example.com/privkey.pem"export GATE_TLS__MIN_VERSION="1.2"export GATE_TLS__MAX_VERSION="1.3"
# Loggingexport GATE_OBSERVABILITY__LOGGING__LEVEL="debug"export GATE_OBSERVABILITY__LOGGING__FORMAT="json"export GATE_OBSERVABILITY__LOGGING__OUTPUT="stdout"
# Metricsexport GATE_OBSERVABILITY__METRICS__ENABLED=trueexport GATE_OBSERVABILITY__METRICS__ENDPOINT="/metrics"export GATE_OBSERVABILITY__METRICS__PORT=9090
# Tracingexport GATE_OBSERVABILITY__TRACING__ENABLED=trueexport GATE_OBSERVABILITY__TRACING__SAMPLING_RATE=0.1export GATE_OBSERVABILITY__TRACING__ENDPOINT="http://tempo:4317"
# Custom servers directoryexport GATE_SERVERS_DIR="/custom/path/to/servers"Priority
Section titled “Priority”Environment variables have the highest priority and will override any file-based configuration.
Server Settings
Section titled “Server Settings”Basic Configuration
Section titled “Basic Configuration”server: # Bind address host: 0.0.0.0
# HTTP port http_port: 80
# HTTPS port (when TLS is enabled) https_port: 443
# Maximum concurrent connections max_connections: 10000
# Worker threads (null = auto-detect CPU cores) worker_threads: null
# Graceful shutdown timeout (seconds) shutdown_timeout: 30
# Connection timeout (seconds) connection_timeout: 30
# Request timeout (seconds) request_timeout: 60
# Keep-alive timeout (seconds) keep_alive_timeout: 75Understanding Timeouts
Section titled “Understanding Timeouts”| Timeout | Description | Default | When to Adjust |
|---|---|---|---|
connection_timeout | Time to establish connection | 30s | Long-distance clients |
request_timeout | Time to complete request | 60s | Long-running APIs |
keep_alive_timeout | Time to keep idle connections | 75s | Mobile clients |
shutdown_timeout | Time for graceful shutdown | 30s | Long requests |
Worker Threads
Section titled “Worker Threads”# Auto-detect (recommended for most cases)worker_threads: null
# Fixed number (useful for containerized environments)worker_threads: 4
# Match CPU coresworker_threads: 8When to set manually:
- Containerized environments with CPU limits
- Shared hosting with resource constraints
- Optimizing for specific workloads
TLS/HTTPS Configuration
Section titled “TLS/HTTPS Configuration”Basic HTTPS Setup
Section titled “Basic HTTPS Setup”tls: enabled: true auto_redirect_http: true cert_path: /etc/letsencrypt/live/example.com/fullchain.pem key_path: /etc/letsencrypt/live/example.com/privkey.pem min_version: '1.2' max_version: '1.3'Let’s Encrypt with Certbot
Section titled “Let’s Encrypt with Certbot”# Install certbotsudo apt-get install certbot
# Obtain certificatesudo certbot certonly --standalone -d example.com -d www.example.com
# Configure Gatetls: enabled: true auto_redirect_http: true cert_path: /etc/letsencrypt/live/example.com/fullchain.pem key_path: /etc/letsencrypt/live/example.com/privkey.pemDevelopment HTTPS (Self-Signed)
Section titled “Development HTTPS (Self-Signed)”# Generate self-signed certificateopenssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodestls: enabled: true auto_redirect_http: false # Don't force HTTPS in dev cert_path: ./certs/cert.pem key_path: ./certs/key.pemTLS Versions
Section titled “TLS Versions”| Version | Security | Compatibility | Recommendation |
|---|---|---|---|
| 1.0 | ⚠️ Deprecated | High | ❌ Avoid |
| 1.1 | ⚠️ Deprecated | Medium | ❌ Avoid |
| 1.2 | ✅ Secure | High | ✅ Minimum |
| 1.3 | ✅ Most Secure | Modern browsers | ✅ Preferred |
Recommended Configuration:
tls: min_version: '1.2' # Support modern & legacy clients max_version: '1.3' # Use latest securityHigh Security:
tls: min_version: '1.3' # TLS 1.3 only max_version: '1.3'Observability
Section titled “Observability”Logging
Section titled “Logging”observability: logging: # Log level: trace, debug, info, warn, error level: info
# Format: json, text format: json
# Output: stdout, file output: stdoutLog Levels:
| Level | Use Case | Volume |
|---|---|---|
trace | Deep debugging | Very High |
debug | Development | High |
info | Production | Medium |
warn | Production (quiet) | Low |
error | Production (minimal) | Very Low |
Development:
logging: level: debug format: text output: stdoutProduction:
logging: level: info format: json output: stdoutWith RUST_LOG:
You can also use the RUST_LOG environment variable for more granular control:
# Gate at debug, everything else at infoRUST_LOG=gate=debug,hypers=debug,tower_http=info
# Specific module debuggingRUST_LOG=gate::config=trace,gate=debug
# ProductionRUST_LOG=gate=info,hypers=info,tower_http=warnMetrics
Section titled “Metrics”observability: metrics: enabled: true endpoint: /metrics port: 9090 # Optional: separate port for metricsAccessing Metrics:
# Same port as applicationcurl http://localhost:80/metrics
# Separate metrics portcurl http://localhost:9090/metricsIntegration with Prometheus:
scrape_configs: - job_name: 'gate' static_configs: - targets: ['localhost:9090']Tracing
Section titled “Tracing”observability: tracing: enabled: true sampling_rate: 0.1 # 10% of requests endpoint: http://tempo:4317Sampling Rates:
| Rate | Use Case | Overhead |
|---|---|---|
| 1.0 | Development | High |
| 0.1 | Production (10%) | Medium |
| 0.01 | Production (1%) | Low |
Integration with Grafana Tempo:
tracing: enabled: true sampling_rate: 0.1 endpoint: http://tempo:4317Server Configurations
Section titled “Server Configurations”Server configurations define per-domain routing, backends, and middleware.
Proxy Backend Example
Section titled “Proxy Backend Example”~/.config/gate/servers/api.example.com.yml:
name: api-servicehosts: - api.example.com - apis.example.com
backend: service_type: proxy proxy: # Backend servers servers: - url: http://localhost:8000 weight: 100 max_requests: 1000 backup: false
- url: http://localhost:8001 weight: 100 max_requests: 1000 backup: false
- url: http://localhost:8002 weight: 50 max_requests: 500 backup: true # Only used when others fail
# Load balancing load_balancer: strategy: round_robin # round_robin, least_connections, ip_hash sticky_sessions: false cookie_name: session_id cookie_ttl: 3600
# Health checks health_check: enabled: true path: /health interval: 10 # seconds timeout: 3 # seconds healthy_threshold: 2 unhealthy_threshold: 3
# Timeouts and retries timeout: 30 retry: attempts: 3 backoff: exponential # fixed, exponential base_delay: 100 # milliseconds
middleware: - security-headers - rate-limit - corsStatic Files Example
Section titled “Static Files Example”~/.config/gate/servers/www.example.com.yml:
name: websitehosts: - example.com - www.example.com
backend: service_type: static static_files: root: /var/www/example.com index: index.html fallback: 404.html cache_control: 'public, max-age=3600' spa_mode: false
middleware: - compress - cache-headersSPA (Single Page Application)
Section titled “SPA (Single Page Application)”name: spa-apphosts: - app.example.com
backend: service_type: static static_files: root: /var/www/app index: index.html spa_mode: true # All routes fallback to index.html cache_control: 'no-cache'
middleware: - compressRedirect Example
Section titled “Redirect Example”~/.config/gate/servers/redirect.yml:
name: www-redirecthosts: - www.example.com
backend: service_type: redirect redirect: target: https://example.com permanent: true # 301 vs 302 preserve_path: true # example.com/foo → example.com/foo preserve_query: true # Keep ?param=valueMixed Backend Routes
Section titled “Mixed Backend Routes”~/.config/gate/servers/app.example.com.yml:
name: app-servicehosts: - app.example.com
# Default backend (serves SPA)backend: service_type: static static_files: root: /var/www/app index: index.html spa_mode: true
# Route-specific backendsroutes: # API routes → backend service - path: /api/* methods: [GET, POST, PUT, DELETE, PATCH] backend: service_type: proxy proxy: servers: - url: http://localhost:8000 middleware: - auth-required - rate-limit-api priority: 100
# Static assets → CDN - path: /static/* backend: service_type: static static_files: root: /var/www/app/static cache_control: 'public, max-age=31536000, immutable' middleware: - compress priority: 90
# WebSocket → separate service - path: /ws/* backend: service_type: proxy proxy: servers: - url: http://localhost:9000 priority: 95Advanced Topics
Section titled “Advanced Topics”Custom Servers Directory
Section titled “Custom Servers Directory”Override default server configuration directories:
Via config file:
servers_dir: /custom/path/to/serversVia environment:
export GATE_SERVERS_DIR=/custom/path/to/serversFile Organization
Section titled “File Organization”Organize server configs in subdirectories:
~/.config/gate/servers/├── production/│ ├── api.yml│ ├── web.yml│ └── cdn.yml├── staging/│ ├── api.yml│ └── web.yml└── tenants/ ├── customer1.yml ├── customer2.yml └── customer3.ymlAll files are loaded regardless of directory structure.
Multiple Environments
Section titled “Multiple Environments”Development:
# Use repo configcd /path/to/reponx serve gateStaging:
# Use staging configexport GATE_SERVERS_DIR=~/.config/gate-staging/serversgateProduction:
# Use production configgate # Loads from ~/.config/gate/Docker Configuration
Section titled “Docker Configuration”docker-compose.yml:
version: '3.8'
services: gate: image: gate:latest ports: - '80:80' - '443:443' environment: - GATE_SERVER__HTTP_PORT=80 - GATE_SERVER__HTTPS_PORT=443 - GATE_TLS__ENABLED=true - GATE_TLS__CERT_PATH=/certs/fullchain.pem - GATE_TLS__KEY_PATH=/certs/privkey.pem - GATE_OBSERVABILITY__LOGGING__LEVEL=info volumes: - ./config.yml:/etc/gate/gate.config.yml:ro - ./servers:/etc/gate/servers:ro - /etc/letsencrypt:/certs:ro restart: unless-stoppedKubernetes Configuration
Section titled “Kubernetes Configuration”ConfigMap:
apiVersion: v1kind: ConfigMapmetadata: name: gate-configdata: gate.config.yml: | server: host: 0.0.0.0 http_port: 80 observability: logging: level: info format: jsonDeployment:
apiVersion: apps/v1kind: Deploymentmetadata: name: gatespec: replicas: 3 template: spec: containers: - name: gate image: gate:latest ports: - containerPort: 80 env: - name: GATE_TLS__ENABLED value: 'true' - name: GATE_TLS__CERT_PATH value: /certs/tls.crt - name: GATE_TLS__KEY_PATH value: /certs/tls.key volumeMounts: - name: config mountPath: /etc/gate - name: tls mountPath: /certs volumes: - name: config configMap: name: gate-config - name: tls secret: secretName: gate-tlsDebugging Configuration
Section titled “Debugging Configuration”View what config is being used:
Set log level to debug to see which config files are loaded:
GATE_OBSERVABILITY__LOGGING__LEVEL=debug gateOutput will show:
📋 Loaded config from: "/home/user/.config/gate/gate.config.yml"🌐 Loading server configs from: "/home/user/.config/gate/servers"🌐 Loaded 5 server configuration(s)Validate configuration:
# Check if Gate can load configgate --help # (future: gate config validate)Performance Tuning
Section titled “Performance Tuning”High-traffic sites:
server: max_connections: 50000 worker_threads: 16 keep_alive_timeout: 30Resource-constrained environments:
server: max_connections: 1000 worker_threads: 2 keep_alive_timeout: 120WebSocket-heavy workloads:
server: keep_alive_timeout: 300 # 5 minutes request_timeout: 600 # 10 minutesNext Steps
Section titled “Next Steps”- Server Configuration Examples
- Middleware Configuration
- Security Best Practices
- Troubleshooting Guide
Support
Section titled “Support”For issues or questions:
- Check the README.md
- Review sample configs in this directory
- File an issue in the repository