SadServers
  • Scenarios
  • Labs
    All Labs Linux & Bash Web Servers Databases Data Processing Docker Kubernetes CI/CD Infrastructure as Code Tooling / Applications
  • Dashboard
  • Solutions
    For Individuals For Businesses
  • Ranking
  • Newsletter
  • Documentation
    FAQ Support Pro Accounts Pro+ Accounts Business Accounts Gift API CLI/TUI Privacy Troubleshooting Interviews
  • Blog
  • Pricing
  • Gift
    Gift Purchase Gift Redeem
  • About
Log In - Sign Up
  1. Labs
  2. Gunicorn
  3. Cheatsheet

Guide

Concepts and learning path

Troubleshooting

Failure modes and fixes

Cheatsheet

Commands to keep handy

Gunicorn cheatsheet

Running Gunicorn

CommandDescription
gunicorn myapp.wsgi:applicationStart with default bind :8000
gunicorn -w 4 -b 127.0.0.1:8000 app:app4 workers on localhost:8000
gunicorn -c gunicorn.conf.py myapp.wsgi:applicationLoad settings from config file
gunicorn --bind unix:/run/gunicorn.sock ...Listen on Unix socket
gunicorn --chdir /opt/myapp ...Set working directory

Service control (systemd)

CommandDescription
systemctl status gunicornService status
systemctl restart gunicornRestart all workers
systemctl reload gunicornGraceful reload (if unit supports HUP)
journalctl -u gunicorn -fFollow service logs
kill -HUP $(cat /run/gunicorn.pid)Graceful worker restart

Inspection

CommandDescription
ss -tlnp | grep gunicornTCP listeners
ps aux | grep gunicornMaster and worker processes
curl -v http://127.0.0.1:8000/Test app directly (bypass proxy)
ls -la /run/gunicorn.sockUnix socket permissions

Example gunicorn.conf.py

bind = "127.0.0.1:8000" workers = 3 worker_class = "sync" timeout = 30 max_requests = 1000 max_requests_jitter = 50 accesslog = "-" errorlog = "-" capture_output = True

Example systemd unit

[Service] User=deploy Group=deploy WorkingDirectory=/opt/myapp ExecStart=/opt/myapp/venv/bin/gunicorn \ --config /opt/myapp/gunicorn.conf.py \ myproject.wsgi:application Restart=on-failure

nginx proxy to Gunicorn (Unix socket)

location / { proxy_pass http://unix:/run/gunicorn.sock; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

Pro tips

  • Test the WSGI app import manually: python -c "from myapp.wsgi import application"
  • Bind to 127.0.0.1 or a socket — don't expose Gunicorn directly to the internet
  • Use max_requests to mitigate slow memory growth in long-lived workers
  • 502 from nginx usually means Gunicorn is down or the socket path is wrong

Practice scenarios

Hands-on Gunicorn scenarios on live Linux VMs: gunicorn

SadServersSadServers

Real-world Linux and DevOps scenarios for hands-on learning and technical assessment.

Uptime Robot ratio (30 days)
Product
  • Scenarios
  • For Individuals
  • For Businesses
  • Pricing
Resources
  • FAQ
  • Blog
  • Newsletter
Company
  • About Us
  • Support
  • Privacy Policy
  • Terms of Service
  • Contact
Connect With Us
info@sadservers.com

Made in Canada 🇨🇦
Updated: 2026-06-13 16:06 UTC – 2d2950a