0Pricing
Django Academy · Lesson

Nginx as a Reverse Proxy

Front Gunicorn and serve static files.

Nginx as a Reverse Proxy is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Add Nginx

Gunicorn runs your code, but it should not face the raw internet alone. A reverse proxy sits in front and shields it. 🛡️

What a Reverse Proxy Does

A reverse proxy receives every browser request, then forwards it to Gunicorn and relays the answer back. The client never talks to Gunicorn directly.

Nginx Is Fast at Files

Nginx excels at serving static files and handling thousands of connections, freeing Gunicorn to focus only on dynamic Python work.

The Two-Layer Stack

The flow becomes browser to Nginx to Gunicorn to Django. Each layer does what it is best at, giving you speed and safety together.

A Server Block

Nginx config lives in a server block. It listens on a port and names the domain it answers for.

server {
    listen 80;
    server_name example.com;
}

Proxy to Gunicorn

Inside a location, proxy_pass tells Nginx where to send dynamic requests, usually Gunicorn on a local port or socket.

location / {
    proxy_pass http://127.0.0.1:8000;
}

Pass Real Headers

Add proxy_set_header lines so Django sees the true host and client IP, not just Nginx's local address.

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;

Serve Static Directly

Map a location for /static/ to your collected files. Nginx serves them straight from disk, skipping Gunicorn entirely for speed.

location /static/ {
    alias /app/staticfiles/;
}

Where to Connect

Nginx can reach Gunicorn over a TCP port or a faster Unix socket. Sockets avoid network overhead on the same machine.

Test Before Reload

Always check your config with nginx -t before reloading. A bad file caught here saves you from taking the site offline.

nginx -t
systemctl reload nginx

TLS Lives Here Too

Nginx is also the natural place to terminate HTTPS, decrypting traffic once before passing plain requests on to Gunicorn.

Quick Check

Pick the directive that forwards requests to Gunicorn.

Recap

You set up Nginx as a reverse proxy: it fronts Gunicorn with proxy_pass, serves static files fast, forwards headers, and handles HTTPS. 🎯

Frequently asked questions

Is the “Nginx as a Reverse Proxy” lesson free?

Yes — the full text of “Nginx as a Reverse Proxy” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “Nginx as a Reverse Proxy”?

Front Gunicorn and serve static files. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Nginx as a Reverse Proxy” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Gunicorn as the WSGI Server
  2. Nginx as a Reverse Proxy
  3. WhiteNoise for Static Files
  4. Environment Variables and Settings Split
← Back to Django Academy