Prerequisites
Before deploying to production, ensure you have:- Python 3.8 or higher
- PostgreSQL database (recommended) or SQLite
- Access to your production server
- Domain name configured (optional but recommended)
Environment Configuration
Install dependencies
Install production dependencies from Key production packages include:
requirements.txt:gunicorn==22.0.0- Production WSGI serverpsycopg2==2.9.3- PostgreSQL adapterflask_talisman==1.0.0- Security headers and HTTPSFlask-Limiter==3.5.0- Rate limiting
Run database migrations
Gunicorn Configuration
The platform includes a production-readygunicorn.conf.py with optimized settings:
Worker Configuration
Logging
Gunicorn logs to stdout/stderr by default:Process Management
WSGI Entry Point
Thewsgi.py file provides the application object for Gunicorn:
wsgi.py:18-21
Security Considerations
HTTPS Enforcement
Flask-Talisman enforces HTTPS in production mode:app/__init__.py:165-170
Rate Limiting
Built-in rate limiting protects endpoints:app/__init__.py:21-26
Proxy Support
When deployed behind a reverse proxy (nginx, load balancer):app/__init__.py:173
Health Checks
Two endpoints are available for monitoring:Basic Health Check
Readiness Check (with database)
200 if database is accessible, 503 if degraded.
See Monitoring and Logging for more details.
Common Deployment Patterns
Systemd Service
Create/etc/systemd/system/mathsoc.service:
Docker Deployment
Example Dockerfile:Nginx Reverse Proxy
Example nginx configuration:Troubleshooting
Application won’t start
Check Gunicorn logs:Database connection errors
VerifyDATABASE_URL or individual database settings in .env. Test connection:
Permission errors
Ensure the application user has write access to:app/static/uploads/- for file uploads/tmp/gunicorn.pid- for PID file
Next Steps
Database Migrations
Learn how to manage database schema changes
Monitoring
Set up logging and monitoring