Nginx als Reverse Proxy
Gunicorn vorschalten und statische Dateien bereitstellen
Nginx als Reverse Proxy ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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 nginxTLS 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. 🎯
Häufig gestellte Fragen
Ist die Lektion „Nginx als Reverse Proxy“ kostenlos?
Ja — der vollständige Text von „Nginx als Reverse Proxy“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Nginx als Reverse Proxy“?
Gunicorn vorschalten und statische Dateien bereitstellen Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Django Academy zu starten?
Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Nginx als Reverse Proxy“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?
Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Gunicorn als WSGI-Server
- Nginx als Reverse Proxy
- WhiteNoise für statische Dateien
- Umgebungsvariablen und Aufteilung der Einstellungen