Gunicorn Local Python Web Development Guide
Run Django, Flask, and other Python WSGI applications on localhost using Gunicorn, default binding to 127.0.0.1:8000.
Gunicorn (Green Unicorn) is a Python WSGI HTTP server commonly used with Nginx in production environments. It can be used to simulate production deployment locally when developing with Django or Flask.
Default localhost Access
| Purpose | Address |
|---|---|
| Default Bind | http://127.0.0.1:8000 |
| localhost Equivalent | http://localhost:8000 |
By default, it listens on port 8000, accessible only from the local machine (127.0.0.1).
Installation and Running
pip install gunicornFlask Example
gunicorn -w 4 -b 127.0.0.1:8000 app:appDjango Example
gunicorn myproject.wsgi:application -b localhost:8000-w 4 indicates 4 worker processes.
Development Comparison
For daily development, Django/Flask typically use the built-in server:
python manage.py runserver # Django → http://localhost:8000
flask run # Flask → http://localhost:5000Gunicorn is suitable for local stress testing before deployment or for debugging with Nginx.
Binding Ports
gunicorn -b 0.0.0.0:8080 app:appThis allows access from the local area network; the local machine still uses http://localhost:8080.
Common Issues
ModuleNotFoundError
Ensure the virtual environment is activated and the app:app module path is correct.
Address already in use
Change the -b port or terminate the process occupying port 8000.
Summary
Gunicorn defaults to http://localhost:8000 for production-level local running of Python WSGI applications.