DEV Community

Ruben Voß
Ruben Voß

Posted on

WSGI als Python runtime - Django in Produktion Teil 5

Vorwort

Nun, da wir auf unserem Produktionsserver alles auf unsere django - Webapp vorbereitet haben, ist als nächstes Gunicorn dran. Gunicorn wird unsere app - so wie python manage.py runserver in der Entwicklung, in Produktion zum laufen bringen.

Installation in requirements.txt

Jetzt sollte unsere requirements - Datei zumindestens folgendes enthalten:

# django
django==5.0.4

# postgresql database adapter
psycopg2==2.9.9
psycopg2-binary==2.9.9

# webserver in production
gunicorn==21.2.0
Enter fullscreen mode Exit fullscreen mode

in Entwicklung und Produktion mit pip install -r requirements.txt installieren

Erster Start

Jetzt kannst du den WSGI server das erste mal starten, am besten bei dir Lokal in der Entwicklungsumgebung.

cd meine_repository/meine_app
gunicorn meine_app.wsgi

# so sollte dein Output ausschauen:
[2024-05-26 22:25:05 +0200] [71525] [INFO] Starting gunicorn 21.2.0
[2024-05-26 22:25:05 +0200] [71525] [INFO] Listening at: http://127.0.0.1:8000 (71525)
[2024-05-26 22:25:05 +0200] [71525] [INFO] Using worker: sync
[2024-05-26 22:25:05 +0200] [71526] [INFO] Booting worker with pid: 71526
--- Using development Settings ---
Enter fullscreen mode Exit fullscreen mode

Nun sollte deine app in der Produktionsversion lokal bei dir laufen. Gehe einfach auf http://127.0.0.1:8000 und du kannst sie dir anschauen.

Das kannst du nun so auch auf deinem Server ausführen, aber du wirst deine App wahrscheinlich nicht unter deiner Domain / ip erreichen können. Um das zu können musst du mit nginx deinen Webserver als Reverse-Proxy weiterleiten. Damit geht's beim nächsten mal weiter.
Hier kannst du mehr über nginx als Reverse Proxy herausfinden.

PS: Viel Spaß beim Coden,
Dein Ruben

Mein Blog

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay