Gunicorn como servidor WSGI
Sirva o Django com um servidor de aplicações real
Gunicorn como servidor WSGI é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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. 🎯
Aprenda Python com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 30
- Aulas
- 120
Perguntas Frequentes
A aula “Gunicorn como servidor WSGI” é grátis?
Sim — o texto completo de “Gunicorn como servidor WSGI” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.
O que vou aprender em “Gunicorn como servidor WSGI”?
Sirva o Django com um servidor de aplicações real Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Django Academy?
Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Gunicorn como servidor WSGI”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Django Academy?
Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Gunicorn como servidor WSGI
- Nginx como proxy reverso
- WhiteNoise para arquivos estáticos
- Variáveis de ambiente e divisão das configurações