Deploy Django on Apache
This template shows the shape of an Apache reverse-proxy setup for a Django
application served by gunicorn or uwsgi.
What It Needs
- Apache with
mod_proxy,mod_proxy_http, andmod_ssl. - A Django backend listening on
localhostor a private network port. - A virtual host that terminates TLS and forwards requests.
Typical Virtual Host
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/example.crt
SSLCertificateKeyFile /etc/ssl/private/example.key
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
</VirtualHost>
Django Side
- Serve static files separately, usually through Apache or a CDN.
- Keep application secrets out of the Apache config.
- Make sure the app trusts the proxy headers if needed.
Practical Notes
- Redirect HTTP to HTTPS.
- Test the backend directly before blaming Apache.
- Use logs from both Apache and the app when debugging.