Gunicorn como servidor WSGI
Sirva Django con un servidor de aplicaciones real
Gunicorn como servidor WSGI es una lección gratuita de Django Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Django Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Django Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Meet Gunicorn
Django's runserver is great for coding, but it is single-threaded and unsafe for the public web. In production you need a real app server. 🚀
What WSGI Is
WSGI is the standard contract between a Python web app and a server. It lets any server talk to Django without knowing its internals.
Gunicorn Speaks WSGI
Gunicorn is a production WSGI server that loads your Django app and runs it fast, stable, and concurrently across many requests.
Install It
Add Gunicorn to your environment with pip, then pin it in requirements.txt so every deploy uses the same version.
pip install gunicorn
pip freeze > requirements.txtThe wsgi.py Entry Point
Every project ships a wsgi.py exposing an object named application. Gunicorn imports exactly that object to serve your site.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()Run Gunicorn
Point gunicorn at your project's wsgi module. The dotted path mirrors how Python imports it, ending in application.
gunicorn myproject.wsgi:applicationBind an Address
Use --bind to choose the host and port. Binding to 0.0.0.0 lets the outside world reach the server, not just localhost.
gunicorn myproject.wsgi --bind 0.0.0.0:8000Workers Handle Load
Each worker is a process serving requests in parallel. A common start is 2 times CPU cores plus 1, then tune from real traffic.
gunicorn myproject.wsgi --workers 3Gunicorn Is Not for Static
Gunicorn runs your Python code, not files. Serving CSS and images is a job you hand to Nginx or WhiteNoise instead.
Keep It Running
A live server must survive reboots and crashes. A process manager like systemd restarts Gunicorn automatically so your site stays up.
Timeouts Matter
The --timeout flag kills workers stuck on slow requests. The default is 30 seconds, which protects you from one hung view freezing everything.
gunicorn myproject.wsgi --timeout 60Quick Check
Let's confirm what Gunicorn actually serves.
Recap
You learned that Gunicorn is the production WSGI server that runs Django via wsgi:application, scales with workers, and leaves static files to others. 🎯
Aprende Python con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 30
- Lecciones
- 120
Preguntas frecuentes
¿La lección «Gunicorn como servidor WSGI» es gratis?
Sí — el texto completo de «Gunicorn como servidor WSGI» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Django Academy, actualiza a CoddyKit PRO. El curso de Django Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Gunicorn como servidor WSGI»?
Sirva Django con un servidor de aplicaciones real Practicas Django Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Django Academy?
No se requiere experiencia previa. Django Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Gunicorn como servidor WSGI»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Django Academy?
Sí. Cada lección de Django Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Gunicorn como servidor WSGI
- Nginx como proxy inverso
- WhiteNoise para archivos estáticos
- Variables de entorno y separación de ajustes