Topic · Serving the app

Gunicorn & app servers for Django in production

The WSGI and ASGI servers that run Django: Gunicorn, uWSGI, Uvicorn, Granian, and mod_wsgi, and how their workers fail.

capacity is workers × threadsMasterbinds, supervisesWorker 1threadthreadthreadWorker 2threadthreadthreadWorker 3threadthreadthreadMemory grows with workers; database connections grow with threads

Gunicorn, Uvicorn, uWSGI, and Granian turn Django into a process that serves HTTP. Their settings decide your capacity, memory use, and how slow requests affect everyone else.

The guides cover running them correctly, sizing workers and threads, and fixing the errors they produce: boot failures, timeouts, OOM kills, and address conflicts.

17Set it up
6Run it well
1Check it
23Fix it

Set it up

Guides that take this from nothing to running in production.

  • Deploy Django with uWSGI and Nginx

    Run Django with uWSGI and Nginx: a strict uWSGI ini, socket permissions, systemd integration, graceful reloads, harakiri timeouts, and checks.

  • Deploy Django with Apache and mod_wsgi

    Deploy Django on Apache with mod_wsgi daemon mode, a matching virtualenv, static file aliases, secret loading, HTTPS, and code reloads without restarting Apache.

  • Deploy Django with Granian

    Run Django in production with Granian, the Rust HTTP server for Python: WSGI and ASGI interfaces, workers and threads, a systemd unit, Nginx in front, and when to choose it.

  • Deploy Django on Windows Server With IIS

    Deploy Django on Windows Server behind IIS: run Waitress through HttpPlatformHandler instead of the unmaintained wfastcgi, serve static files from IIS, run it under an app pool identity, and add HTTPS with an IIS binding.

  • Run Django With Hypercorn

    Run Django in production with Hypercorn, an ASGI and WSGI server with HTTP/2 and HTTP/3 support: configure workers and worker class, bind behind Nginx, set timeouts and graceful shutdown, and compare it with Uvicorn and Gunicorn.

  • Deploy Django With NGINX Unit

    Run Django on NGINX Unit, the application server configured through a JSON API: configure a Python application with a virtualenv, route static files, set processes, add TLS, and check the project's maintenance status before adopting it.

  • Write a gunicorn.conf.py for Django

    Configure Gunicorn for Django with a gunicorn.conf.py file: bind, workers and threads, timeouts, max_requests with jitter, logging to stdout, forwarded headers, preload trade-offs, and server hooks for database connections.

  • Gunicorn vs uWSGI for Django

    Compare Gunicorn and uWSGI for serving Django in production: configuration complexity, performance, worker models, features like the uwsgi protocol and emperor mode, maintenance status, and which to choose for new and existing projects.

  • Gunicorn vs Uvicorn for Django

    Compare Gunicorn and Uvicorn for Django: WSGI versus ASGI, when async views and WebSockets need Uvicorn, running Uvicorn workers under Gunicorn, performance for typical database-bound apps, and how to choose.

  • Why You Should Not Use runserver in Production

    Why Django’s manage.py runserver is not for production: single-process design, no security review, static file handling, auto-reload, and DEBUG coupling, plus what to run instead with Gunicorn, Uvicorn, and a reverse proxy.

  • Deploy Django With mod_wsgi-express

    Run Django in production with mod_wsgi-express: install mod_wsgi with pip into the virtualenv, generate a self-contained Apache configuration, serve static files, run it under systemd, and put it behind Nginx or use it directly on port 80.

  • Run Django in Production on Windows With Waitress

    Run Django on a Windows server with Waitress: install it in a virtualenv, serve the WSGI app on a port, run it as a Windows service with NSSM, put IIS or Caddy in front for HTTPS and static files, and tune threads and logging.

  • Django WSGI vs ASGI: Which One Should You Deploy?

    When you deploy Django in production, you will see both WSGI and ASGI recommended.

  • Deploy Django with Gunicorn and Nginx on Ubuntu

    Moving a Django app from local development to production usually fails on the same points: process management, reverse proxy configuration, static files, secrets, TLS, and safe...

  • Deploy Django ASGI with Uvicorn and Nginx

    If you want to deploy Django ASGI with Uvicorn and Nginx, python manage.py runserver is not a production option.

  • How to Configure systemd for Gunicorn and Django

    Running Gunicorn manually for a Django app is fragile. If your SSH session closes, the process can stop.

  • Deploy Django on cPanel Shared Hosting

    Deploy Django on cPanel shared hosting with Setup Python App and Phusion Passenger: create the app and virtualenv, write passenger_wsgi.py, use MySQL or PostgreSQL, serve static files from public_html, and know the hosting limits.

Run it well

Tuning, reliability, and operations once it works.

  • How to Optimize Gunicorn Workers for Django

    If you want to optimize Gunicorn workers for Django, the main production risk is getting concurrency wrong.

  • Use Gunicorn preload_app With Django

    Decide whether to enable Gunicorn preload_app for Django: memory savings from copy-on-write, faster worker boot, fail-fast startup, the database and client connections you must close after fork, and why reloads need a full restart.

  • Run Gunicorn gevent Workers for I/O-Heavy Django Apps

    Use Gunicorn gevent workers for Django apps that spend time waiting on external APIs: worker_connections, monkey patching, psycopg and database connection limits, CPU-bound pitfalls, and comparing gevent with threads and ASGI.

  • Reduce Django Startup and Import Time

    Make Django processes start faster: measure import time with python -X importtime, defer heavy imports, avoid database queries at import, trim INSTALLED_APPS, and why startup matters for serverless, autoscaling, deploys, and management commands.

  • Graceful Shutdown for Django and Celery (SIGTERM)

    Shut down Django web servers and Celery workers without dropping requests or tasks: how Gunicorn, Uvicorn, and Celery handle SIGTERM, graceful timeouts, Docker stop_grace_period, Kubernetes preStop and terminationGracePeriodSeconds, and PID 1 pitfalls.

  • Reduce Django Memory Usage per Worker

    Lower the memory footprint of Django processes: measure RSS per Gunicorn and Celery worker, trim imports and INSTALLED_APPS, stream large querysets and responses, recycle workers with max-requests, try jemalloc, and size worker counts to fit the server.

Check it

Review lists to run before launch or after a change.

  • Gunicorn Production Checklist for Django

    A production checklist for running Django on Gunicorn: bind address and socket, worker class and count, timeouts and graceful shutdown, worker recycling, logging, forwarded headers, process supervision, and the proxy in front.

Fix it

Errors and symptoms, each traced to a cause and a fix.

Learning paths through this topic

Related topics