Overview
The production settings module atbakerydemo/settings/production.py provides a secure, production-ready configuration for deploying the Wagtail Bakery Demo. This guide covers all configuration options and best practices.
Settings Module Structure
The production settings inherit from base settings:Security Settings
Secret Key
The secret key is used for cryptographic signing:HTTPS and SSL Settings
Production enforces HTTPS by default:| Variable | Description | Default |
|---|---|---|
SECURE_HSTS_SECONDS | Duration for HSTS header | 2592000 (30 days) |
SECURE_REFERRER_POLICY | Referrer policy header | no-referrer-when-downgrade |
Allowed Hosts
Configure which domains can serve your application:Database Configuration
PostgreSQL Connection
The database is configured via theDATABASE_URL environment variable:
The
DATABASE_URL is automatically parsed by dj-database-url (configured in base settings).Cache Configuration
The production settings support both Redis and local memory caching:Redis Cache (Recommended)
| Variable | Description | Priority |
|---|---|---|
REDIS_TLS_URL | Secure Redis connection URL | 1st (preferred) |
REDIS_URL | Standard Redis connection URL | 2nd (fallback) |
- default: General application caching (sessions, views, etc.)
- renditions: Wagtail image rendition caching
Using separate Redis databases (0 and 1) allows independent cache clearing for different cache types.
Static Files and Media
Static Files with WhiteNoise
Production uses WhiteNoise for efficient static file serving:- Compression (gzip, Brotli)
- Cache-friendly filenames with content hashes
- Far-future cache headers
- No CDN required (but compatible)
Media Storage Options
Configure where user-uploaded media files are stored:- AWS S3
- Google Cloud Storage
- Local Storage
Configure AWS S3 for media storage:Required Environment Variables:Optional Variables:
Email Configuration
The default email backend logs emails to console:Configure SMTP Email
To send real emails, override with environment variables in your deployment:You’ll need to add these settings to a custom production settings override or use a service like SendGrid, Mailgun, or AWS SES.
Wagtail Admin Base URL
Set the base URL for admin email notifications:Search Backend
Configure Elasticsearch for advanced search capabilities:If Elasticsearch is not configured, Wagtail falls back to the database search backend.
Frontend Cache Purging
Configure Cloudflare cache purging when content is published:- API Token (Recommended)
- Account-Wide Key
Basic Authentication
Optionally protect staging sites with HTTP basic authentication:Basic auth is useful for protecting staging environments while allowing whitelisted hosts to bypass authentication.
Logging Configuration
Production logging outputs to console (stdout):Console logging is ideal for containerized environments where logs are captured by the container orchestration platform.
Complete Environment Variables Reference
Required Variables
| Variable | Description | Example |
|---|---|---|
DJANGO_SECRET_KEY | Django secret key | your-50-char-secret-key |
DATABASE_URL | PostgreSQL connection URL | postgres://user:pass@host/db |
DJANGO_SETTINGS_MODULE | Settings module | bakerydemo.settings.production |
Recommended Variables
| Variable | Description | Default |
|---|---|---|
DJANGO_ALLOWED_HOSTS | Comma-separated allowed hosts | * |
REDIS_URL or REDIS_TLS_URL | Redis connection URL | None |
PRIMARY_HOST | Primary domain for emails | None |
DJANGO_DEBUG | Enable debug mode | off |
Optional: AWS Configuration
| Variable | Description |
|---|---|
AWS_ACCESS_KEY_ID | AWS access key |
AWS_SECRET_ACCESS_KEY | AWS secret key |
AWS_REGION | AWS region |
AWS_STORAGE_BUCKET_NAME | S3 bucket for media |
AWS_S3_REGION_NAME | S3 region |
AWS_S3_CUSTOM_DOMAIN | Custom domain for S3 |
Optional: Search Configuration
| Variable | Description | Default |
|---|---|---|
ELASTICSEARCH_ENDPOINT | Elasticsearch host | None |
ELASTICSEARCH_PORT | Elasticsearch port | 9200 |
ELASTICSEARCH_USE_SSL | Use SSL | off |
ELASTICSEARCH_VERIFY_CERTS | Verify SSL certificates | off |
Optional: Cache Configuration
| Variable | Description |
|---|---|
FRONTEND_CACHE_CLOUDFLARE_ZONEID | Cloudflare zone ID |
FRONTEND_CACHE_CLOUDFLARE_BEARER_TOKEN | Cloudflare API token |
FRONTEND_CACHE_CLOUDFLARE_TOKEN | Cloudflare API key (legacy) |
FRONTEND_CACHE_CLOUDFLARE_EMAIL | Cloudflare account email |
Optional: Security Configuration
| Variable | Description | Default |
|---|---|---|
SECURE_HSTS_SECONDS | HSTS duration in seconds | 2592000 (30 days) |
SECURE_REFERRER_POLICY | Referrer policy | no-referrer-when-downgrade |
BASIC_AUTH_ENABLED | Enable basic auth | false |
BASIC_AUTH_LOGIN | Basic auth username | wagtail |
BASIC_AUTH_PASSWORD | Basic auth password | wagtail |
BASIC_AUTH_WHITELISTED_HTTP_HOSTS | Bypass auth for hosts | None |
Optional: Google Cloud
| Variable | Description |
|---|---|
GS_BUCKET_NAME | GCS bucket name |
GS_PROJECT_ID | GCP project ID |
Optional: Logging
| Variable | Description | Default |
|---|---|---|
DJANGO_LOG_LEVEL | Django log level | INFO |
Best Practices
Environment Variable Management
Environment Variable Management
Recommendations:
- Use a secrets management service (AWS Secrets Manager, HashiCorp Vault)
- Never commit
.envfiles with real credentials to version control - Use different credentials for staging and production
- Rotate secrets regularly
- Use strong, randomly generated values
.env.example for documentation:Security Hardening
Security Hardening
Additional security measures:
- Database: Use SSL connections (
?sslmode=require) - Redis: Use TLS connections (
REDIS_TLS_URL) - ALLOWED_HOSTS: Never use
*in production - SECRET_KEY: Minimum 50 characters, truly random
- HSTS: Consider increasing to 1 year after testing
- CSP: Consider adding Content Security Policy headers
Performance Optimization
Performance Optimization
Optimize production performance:
- Redis: Always use Redis cache in production
- Database: Use connection pooling
- Static Files: WhiteNoise handles this efficiently
- Media Files: Use CDN with S3/GCS
- Search: Use Elasticsearch for better performance
- Caching: Configure image renditions cache separately
Monitoring and Observability
Monitoring and Observability
Add monitoring:
- Application monitoring (New Relic, DataDog)
- Error tracking (Sentry)
- Log aggregation (Papertrail, Loggly)
- Uptime monitoring (Pingdom, UptimeRobot)
- Database monitoring (pg:diagnose on Heroku)
Next Steps
Docker Deployment
Deploy with Docker and docker-compose
Heroku Deployment
Deploy to Heroku platform
Configuration Guide
Learn about configuration options
Deployment Overview
Review deployment strategies

