Prerequisites
Before setting up production:- A production server (Ubuntu 20.04+ or Debian 10+ recommended)
- Root or sudo access
- Domain name pointing to your server (for SSL)
- Existing bench with sites and apps configured
- At least 2GB RAM (4GB+ recommended)
Understanding Production Setup
Production setup installs and configures:- NGINX: Web server and reverse proxy
- Supervisor or systemd: Process management
- fail2ban: Intrusion prevention
- Redis: Configured for production
- Proper file permissions and security
Setup Production
Replace
[frappe-user] with the system user that owns the bench directory (typically your username).Production Architecture
Process Management
Bench uses either supervisor or systemd to manage processes:Supervisor (default)
Configuration:config/supervisor.confSymlinked to:
/etc/supervisor/conf.d/[bench-name].conf
Manage processes:
Systemd
To use systemd instead of supervisor, set insites/common_site_config.json:
NGINX Configuration
Configuration:config/nginx.confSymlinked to:
/etc/nginx/conf.d/[bench-name].conf
Key NGINX features:
- Serves static assets directly
- Proxies dynamic requests to Gunicorn
- WebSocket support for socketio
- Gzip compression
- Client body size limits
- Rate limiting (optional)
Regenerate NGINX config:
Redis Configuration
Production uses separate Redis instances:- redis-cache: Port 13000 - Session and cache data
- redis-queue: Port 11000 - Background job queue
- redis-socketio: Port 13000 - Real-time updates
config/redis_*.conf
Configuring Production
Enable production features
Editsites/common_site_config.json:
Auto-restart on updates
Enable automatic service restart afterbench update:
Configure workers
Worker processes are automatically calculated based on CPU cores. To customize:HTTP timeout
For long-running requests:Managing Production Bench
Updating applications
Restarting services
Restart all bench services:Monitoring logs
Supervisor logs:Site maintenance
Put site in maintenance mode:Security Hardening
Firewall setup
Configure firewall to allow only necessary ports:Change SSH port
fail2ban configuration
fail2ban is automatically installed with production setup. Configure NGINX jail:--maxretry: Number of failures before ban (default: 6)--bantime: Ban duration in seconds (default: 600)--findtime: Time window for counting failures (default: 600)
Disable developer mode
Ensure developer mode is off for all sites:Set up sudoers
Allow bench commands without password (already done in production setup):Backup Strategy
Automated backups
Set up automatic daily backups:Manual backups
Backup single site:sites/[sitename]/private/backups/
Restore from backup
Performance Optimization
Enable rate limiting
Editsites/common_site_config.json:
Configure caching
Enable Redis caching in site config:Optimize database
Regularly optimize MariaDB tables:Disabling Production
To revert to development mode:- NGINX configuration symlinks
- Supervisor configuration symlinks
- Reloads services
bench start for development.
Production Checklist
common_site_config.jsonsudo bench setup production [user]Next Steps
- Set up SSL certificates with Let’s Encrypt
- Configure multitenancy for multiple domains
- Review troubleshooting guide for common issues
- Learn about updating and maintenance