Overview
Bare metal deployment installs FootyCollect directly on your server without containerization:- Nginx: Reverse proxy and SSL termination
- Gunicorn: WSGI application server
- Systemd: Service management and process supervision
- PostgreSQL: Database server
- Redis: Cache and Celery broker
- Supervisor: Celery worker management (optional)
Prerequisites
- Ubuntu 20.04+ or Debian 11+ server
- Root or sudo access
- Domain name with DNS pointing to your server
- Minimum 2GB RAM, 20GB disk space
Initial Server Setup
Automated Setup Script
The repository includes an automated setup script (deploy/setup.sh:1) that configures your server:Copy Setup Script
SSH into Server
Run Setup Script
- Update system packages
- Install Python 3.12, PostgreSQL, Redis, Nginx
- Install certbot for SSL certificates
- Create
footycollectuser - Configure PostgreSQL database
- Setup firewall (UFW)
- Configure fail2ban
- Setup log rotation
Set Database Password
Manual Setup (Alternative)
If you prefer manual setup or need to customize the installation:Update System
Update System
Install Dependencies
Install Dependencies
Create Application User
Create Application User
Configure PostgreSQL
Configure PostgreSQL
Configure Redis
Configure Redis
Configure Firewall
Configure Firewall
Enable Fail2ban
Enable Fail2ban
Application Deployment
1. Clone Repository
Switch to the application user and clone the repository:2. Setup Virtual Environment
3. Configure Environment Variables
Copy the environment template and configure production settings:4. Setup Database
Run migrations and create a superuser:5. Configure Nginx
Copy and configure the Nginx reverse proxy (deploy/nginx.conf:1):- HTTP to HTTPS redirect (nginx.conf:6)
- Security headers (nginx.conf:40)
- Gunicorn proxy on 127.0.0.1:8000 (nginx.conf:62)
- Static/media file serving (nginx.conf:77)
- Health check endpoints (nginx.conf:93)
6. Setup SSL Certificates
Obtain free SSL certificates from Let’s Encrypt:- Obtain SSL certificates
- Update Nginx configuration automatically
- Setup auto-renewal via systemd timer
sudo systemctl status certbot.timer7. Configure Gunicorn Service
Setup systemd service for Gunicorn (deploy/gunicorn.service:1):- Workers: 3 (adjust based on CPU cores:
(2 * cores) + 1) - Bind: 127.0.0.1:8000 (Nginx proxies to this)
- Timeout: 120 seconds
- Max requests: 1000 (workers restart after to prevent memory leaks)
8. Verify Deployment
Check that everything is running:Deployment Updates
Use the automated deployment script (deploy/deploy.sh:1) for updates:Backup Database
Update Dependencies
Pull Latest Code
Run Migrations
Collect Static Files
Django Checks
Restart Gunicorn
Reload Nginx
Health Check
/var/www/footycollect/backups/ and automatically rotated (keeps last 7 backups).Service Management
Gunicorn Service
Nginx Service
PostgreSQL
Redis
Celery Workers (Background Tasks)
Setup Celery for background tasks (image downloads, scheduled tasks):Using Supervisor
Create supervisor configuration:Database Backups
Manual Backup
Automated Backups (Cron)
Setup daily backups via cron:Restore Backup
Static and Media Files
Production serves static/media from S3 or R2 (configured in.env).
Collect Static Files
Local Static Files (Not Recommended)
For testing only, serve files locally via Nginx (already configured in nginx.conf:77):Monitoring and Logs
Application Logs
Log Rotation
Log rotation is configured by setup.sh:93:Troubleshooting
Gunicorn Won’t Start
Check service status and logs
Check service status and logs
Verify virtual environment
Verify virtual environment
Check permissions
Check permissions
Verify environment file
Verify environment file
Nginx 502 Bad Gateway
Check Gunicorn is running
Check Gunicorn is running
Check Nginx configuration
Check Nginx configuration
Check Nginx error logs
Check Nginx error logs
Database Connection Errors
Check PostgreSQL is running
Check PostgreSQL is running
Verify DATABASE_URL
Verify DATABASE_URL
Check PostgreSQL logs
Check PostgreSQL logs
Static Files Not Loading
Check S3/R2 configuration
Check S3/R2 configuration
Verify collectstatic ran
Verify collectstatic ran
Check storage credentials
Check storage credentials
SSL Certificate Issues
Certificate not issued
Certificate not issued
Port 80 blocked
Port 80 blocked