Production Setup
Guides, route-group overviews, and live schema entry points for the Plexichat backend.
Production setup
Deploy Plexichat to production with security, TLS, and scaling.
Pre-production checklist
Before you deploy, verify the following:
- You generate strong, unique values for
POSTGRES_PASSWORD,VALKEY_PASSWORD,S3_ACCESS_KEY,S3_SECRET_KEY, andBACKUP_RESTIC_PASSWORDwith the environment generator oropenssl rand -base64 32. - You store
.envoutside version control (for example, HashiCorp Vault, AWS Secrets Manager, or GitLab CI secrets). - You obtain valid TLS certificates or plan to replace the self-signed
certsvolume. - You configure firewall rules to expose only 80 and 443.
- You test restic backups and restores.
- You configure monitoring for
/api/v1/readyand/api/v1/health.
Production startup
Set hardened values in plexichat/.env, then start the stack:
docker compose up -d
Verify health:
docker compose ps
curl -sf http://localhost:8000/api/v1/ready
curl -sf http://localhost:8000/api/v1/health | jq .
Capture the bootstrap admin password
On the first start of a fresh install the backend prints the generated
admin password once to the container console:
docker compose logs backend | grep -A 6 "FIRST BOOT"
The plaintext password is never written to disk or log files by default —
only the console line above and the Argon2id hash exist. If console capture
is not possible, set PLEXICHAT_SAVE_ADMIN_CREDENTIALS=1 in .env before
first boot; the credentials are then written 0600 (atomically) to
~/.plexichat/admin_credentials.txt, and startup fails hard if that secure
write cannot be completed. Store the password, delete any file, change the
password on first login, and set up 2FA.
Security hardening
1. Use strong secrets
Generate passwords:
openssl rand -base64 32
Update plexichat/.env:
POSTGRES_PASSWORD=<32-char-random-value>
VALKEY_PASSWORD=<32-char-random-value>
S3_ACCESS_KEY=<random-access-key>
S3_SECRET_KEY=<random-secret-key>
BACKUP_RESTIC_PASSWORD=<random-restic-password>
The Compose file enforces required secrets and fails fast if they are empty (plexichat/docker-compose.yml, plexichat/docker-compose.yml, plexichat/docker-compose.yml).
Never commit .env to Git. Store secrets in a secret manager.
2. Configure TLS and HTTPS
The cert-init service (plexichat/docker-compose.yml) generates a self-signed certificate in the certs volume on first boot. Nginx uses it at /etc/nginx/certs/fullchain.pem and /etc/nginx/certs/privkey.pem (plexichat-client/docker/nginx/default.conf:21).
For production, replace it with a valid certificate:
Obtain a certificate with Let's Encrypt:
certbot certonly --standalone -d yourdomain.comCopy the certificate into the
certsvolume:docker compose exec client sh -c "cat > /tmp/fullchain.pem" < /etc/letsencrypt/live/yourdomain.com/fullchain.pem docker compose exec client sh -c "cat > /tmp/privkey.pem" < /etc/letsencrypt/live/yourdomain.com/privkey.pem docker compose cp /tmp/fullchain.pem client:/etc/nginx/certs/fullchain.pem docker compose cp /tmp/privkey.pem client:/etc/nginx/certs/privkey.pem docker compose restart clientAlternatively, mount your host certificate directory as a volume override for
client.If you use a custom Nginx configuration path, update
plexichat-client/docker/nginx/default.conf:21.
HTTP on port 80 redirects to HTTPS (plexichat-client/docker/nginx/default.conf:1).
3. Isolate the network
All services share plexichat_default. Only these host ports are published by default:
client: 80/TCP, 443/TCP (plexichat/docker-compose.yml)backend: 8000/TCP, 30000–30100/UDP (plexichat/docker-compose.yml)
The following services are internal-only and use expose instead of ports:
db:5432,valkey:6379,rustfs:9000/9001,clamav:3310,meilisearch:7700,elasticsearch:9200
External traffic reaches only Nginx. Restrict direct backend access with a firewall if you keep 8000 published:
# Allow HTTP and HTTPS, block direct backend access from the public interface
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 8000 -j DROP
For internal RustFS debugging, add a temporary ports override as described in Docker deployment guide instead of publishing it permanently.
4. Run the backend as non-root
The backend image runs as the unprivileged user plexichat (UID 10001) (plexichat/Dockerfile:34). The image creates and owns /home/plexichat/.plexichat (the user's $HOME) so the plexichat_home volume inherits correct ownership. It must not live under /root: that directory is mode 0700 owned by root, so UID 10001 cannot traverse it and the server exits with PermissionError while creating its logs directory.
Verify the runtime user:
docker compose exec backend id
# uid=10001(plexichat) gid=10001(plexichat)
5. Set resource limits
Add limits in plexichat/docker-compose.yml. For example:
backend:
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '1'
memory: 2G
db:
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '1'
memory: 2G
clamav:
deploy:
resources:
limits:
memory: 4G
ClamAV loads signatures into memory (~1.2 GB baseline, ~2.4 GB during reloads). Reserve at least 2 GB for it.
6. Protect logs
Logs may contain sensitive data. Restrict access or forward logs centrally:
# Example log driver in docker-compose.yml
services:
backend:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
Or forward with syslog:
docker compose logs -f backend | logger -t plexichat-backend
Scaling considerations
Cross-worker architecture
Plexichat supports horizontal scaling with multiple Uvicorn workers behind Nginx. Each worker runs the full FastAPI application. Valkey coordinates state across workers.
How it works:
- Session tracking - Each worker registers WebSocket connections in Valkey with a unique
worker_id.SessionManageruses Valkey sets (user:{id}:connections) and hashes (conn:{id}:info) so every worker has a global view of connections. - Event dispatch - When a worker emits an event (for example, a new message),
EventManagersends it to local connections and publishes it to the Valkey pub/sub channelplexichat:events:cross_worker. Each other worker's cross-worker listener dispatches the event to its own local WebSocket connections. - Loop avoidance - Each published message includes the publisher's worker ID. The listener ignores its own echoes, so events are not delivered twice.
- Reconnection - The listener reconnects with exponential backoff (1 s to 60 s cap) if Valkey disconnects.
Prerequisites for multi-worker scaling:
- Valkey must be enabled. Set
valkey.enabled: trueinplexichat/config/docker-config.yamland ensure thevalkeyservice ishealthy. - Rate limiting must use Valkey or database storage. In-memory limiters have independent counters per worker and allow bypass. The server logs a warning if it detects this.
- Snowflake IDs use
worker_id(0–31) anddatacenter_idto generate globally unique, time-sortable IDs.
Run multiple workers:
# Uvicorn directly
uvicorn src.api.app:create_app --host 0.0.0.0 --port 8000 --workers 4
# With Docker Compose (remove the backend ports mapping first)
docker compose up --scale backend=4 -d
When you scale to more than one replica, comment out the ports section on backend (plexichat/docker-compose.yml). Host ports 8000/TCP and 30000–30100/UDP can bind only once. Nginx at :443 load-balances to backend:8000 with ip_hash for sticky WebSocket sessions (plexichat-client/docker/nginx/default.conf:12).
Monitor worker health:
- Admin Panel > Dashboard - Shows the Cross-Worker Event Dispatch card with listener status (
connected,reconnecting,disconnected), backoff, and poll count. GET /api/v1/health- Returnscross_worker_listenerwith the same fields plusenabled(src/api/routes/health.py).GET /api/v1/admin/dashboard- Includesworker_health.
Single-host deployment (recommended for Proxmox)
Use this for 1–50 concurrent users and up to 100K messages per day:
docker compose up -d
Resource guidance:
- CPU: 2–4 cores
- RAM: 4–8 GB (8 GB recommended when ClamAV is enabled)
- Storage: 50–500 GB (depends on media volume)
Multi-host deployment (Kubernetes)
For larger scale, move to Kubernetes:
- Use a managed PostgreSQL service (for example, AWS RDS).
- Use a managed Valkey or Redis service (for example, AWS ElastiCache).
- Run backend replicas across nodes.
- Use an ingress controller for TLS and routing.
- Provision persistent volumes for media or use S3.
Proxmox-specific notes
For Proxmox VMs or LXC containers:
Recommended VM: 2–4 vCPUs, 8 GB RAM, 100 GB SSD, 1 Gbps network.
Performance tuning: Enable nested virtualization only if you run nested VMs. Use snapshot schedules for backups.
ARM64 support: Images are multi-arch. Build for ARM hosts:
docker buildx build --platform linux/arm64 -t plexichat:latest -f plexichat/Dockerfile plexichatOr let Docker auto-detect the platform:
docker compose up -d
Database configuration
Connection pooling (production)
Tune pool settings in plexichat/.env (see plexichat/.env.example:28):
DB_POOL_MIN_CONNECTIONS=20
DB_POOL_MAX_CONNECTIONS=100
DB_POOL_CONNECT_TIMEOUT=10
DB_POOL_MAX_IDLE_TIME=300
Adjust based on concurrent WebSocket connections, request rate, and query complexity. See Connection pooling.
Backups
The backup service (plexichat/docker-compose.yml) uses restic for daily, encrypted, deduplicated snapshots at 02:00 by default. It backs up the PostgreSQL dump, plexichat_home, and RustFS data.
Configure backups in plexichat/.env (see docker/README.md):
| Variable | Default | Description |
|---|---|---|
BACKUP_RESTIC_PASSWORD |
Required | Restic repository password |
BACKUP_SCHEDULE |
0 2 * * * |
Cron schedule (supercronic) |
BACKUP_KEEP_DAILY |
7 |
Daily snapshots to keep |
BACKUP_KEEP_WEEKLY |
4 |
Weekly snapshots to keep |
BACKUP_KEEP_MONTHLY |
6 |
Monthly snapshots to keep |
BACKUP_KEEP_YEARLY |
0 |
Yearly snapshots to keep |
Common commands:
# Run a backup now
docker compose exec backup /scripts/backup.sh run
# List snapshots
docker compose exec backup /scripts/backup.sh list
# Restore the database from the latest snapshot
docker compose exec backup /scripts/backup.sh restore-db latest
# Restore all files to /tmp/restore inside the backup container
docker compose exec backup /scripts/backup.sh restore latest /tmp/restore
Set BACKUP_SECONDARY_REPO to replicate snapshots to S3, SFTP, or B2.
Upgrade procedure
Stop services:
docker compose stopBack up the database:
docker compose exec db pg_dump -U plexichat plexichat > backup.sqlPull the new version:
git pull origin mainRebuild images:
docker compose build --no-cacheStart with automatic migrations:
docker compose up -dVerify health:
docker compose ps curl -sf http://localhost:8000/api/v1/readyTo roll back:
docker compose stop cat backup.sql | docker compose exec -T db psql -U plexichat plexichat docker compose up -d
Monitoring and alerting
Built-in health
Check the readiness probe (Docker health check at plexichat/docker-compose.yml and plexichat/Dockerfile:43):
curl -sf http://localhost:8000/api/v1/ready
Check deep health (DB, Valkey, cross-worker listener):
curl -sf http://localhost:8000/api/v1/health | jq .
View backend logs:
docker compose logs backend --tail 100 | grep -E "ALERT|WARNING|ERROR"
External monitoring
Prometheus: Scrape /api/v1/health and /api/v1/ready. There is no dedicated /metrics endpoint.
scrape_configs:
- job_name: 'plexichat'
static_configs:
- targets: ['localhost:8000']
metrics_path: '/api/v1/health'
Backup health: The backup service reports liveness through /scripts/healthcheck.sh (plexichat/docker-compose.yml). Check docker compose ps backup.
Next steps
- Configuration - Customize settings.
- Health checks - Configure service health.
- Backup & recovery - Test restore procedures.