Overview
This guide covers production deployment best practices for Codex-LB, including:- Reverse proxy setup (Nginx, Caddy, Traefik)
- SSL/TLS termination
- Database selection and tuning
- Security hardening
- Monitoring and logging
- Backup strategies
Architecture
A typical production setup:Prerequisites
- Linux server (Ubuntu 22.04+ recommended)
- Docker and Docker Compose installed
- Domain name with DNS configured
- SSL certificate (Let’s Encrypt recommended)
Database Selection
SQLite (Default)
When to use:- Single-instance deployments
- Low to medium concurrency (< 100 req/s)
- Simple setup requirements
- Zero configuration
- No separate database server
- Built-in automatic backups before migrations
- Not suitable for multi-instance deployments
- Limited concurrent write performance
PostgreSQL (Recommended for Production)
When to use:- High concurrency requirements
- Multi-instance deployments (horizontal scaling)
- Managed database infrastructure
- Better concurrent write performance
- Native replication and backup tools
- Suitable for load balancing across multiple instances
- Requires separate database service
- More complex setup
Reverse Proxy Setup
Nginx
Create/etc/nginx/sites-available/codex-lb:
Caddy
CreateCaddyfile:
Caddy automatically obtains and renews SSL certificates from Let’s Encrypt.
Traefik
Createdocker-compose.yml with Traefik:
Security Hardening
Environment Variables
Never commit secrets to version control. Use environment files with restricted permissions:Dashboard Authentication
Configure strong authentication in the dashboard:- Navigate to Settings → Security
- Set a strong password (16+ characters)
- Enable TOTP (Time-based One-Time Password) 2FA
- Save recovery codes securely
API Key Authentication
Enable API key authentication to restrict proxy access:- Navigate to Settings → API Key Auth
- Toggle Enable API Key Authentication
- Create API keys in API Keys section
- Set rate limits and model restrictions per key
Firewall Rules
IP Allowlist/Blocklist: Use the built-in firewall to restrict access by IP:- Navigate to Settings → Firewall
- Add allowed IP ranges (CIDR notation)
- Block malicious IPs as needed
Container Security
The Docker image runs as a non-root user:Database Configuration
PostgreSQL Setup
Create database and user:SQLite Tuning
For SQLite production deployments:Backup Strategies
Automated Backups
SQLite
Using cron:PostgreSQL
Using pg_dump:Disaster Recovery
Test restores regularly:Monitoring and Logging
Health Checks
Monitoring endpoint:/healthendpoint returning non-200- Response time > 5 seconds
- Certificate expiration
Application Logs
View logs:Metrics
Prometheus monitoring (future): Codex-LB doesn’t expose Prometheus metrics yet, but you can monitor:- Container metrics (CPU, memory, network)
- PostgreSQL metrics (using postgres_exporter)
- Nginx/Caddy metrics
Performance Optimization
Connection Pooling
PostgreSQL:Caching
Codex-LB caches:- Settings: Invalidated on change
- Rate limit headers: Short TTL for API responses
- Model list: Refreshed periodically from upstream
Horizontal Scaling
With PostgreSQL, you can run multiple Codex-LB instances behind a load balancer:Troubleshooting
High Memory Usage
Check container stats:Slow Database Queries
Enable query logging:SSL Certificate Issues
Check certificate expiration:Maintenance
Updating Codex-LB
Database Maintenance
PostgreSQL VACUUM:Next Steps
- Configuration Reference - All environment variables
- API Documentation - API endpoints and usage
- Client Setup - Connect AI clients
- Monitoring Guide - Advanced monitoring setup