UnderHost
Knowledgebase Docs

Deploy Python Apps on CloudPanel

Deploy Flask, Django, FastAPI on CloudPanel. Virtual environments, Gunicorn, Nginx reverse proxy, systemd services, PM2 process management.

On this page

CloudPanel supports Python applications (Flask, Django, FastAPI) via Nginx reverse proxy + Gunicorn or PM2. Create a virtual environment, install dependencies, run Gunicorn, and proxy traffic through Nginx. CloudPanel handles the Nginx configuration; you manage the application process.

Python on CloudPanel

Architecture:

Client Request → Nginx (port 80/443) → Gunicorn (port 8000) → Python App
  • Nginx acts as reverse proxy, handles SSL, compression
  • Gunicorn runs your Python app on localhost:8000
  • systemd keeps Gunicorn running (auto-restart on crash)

Virtual Environments

# Create venv in app directory
python3 -m venv venv

# Activate venv
source venv/bin/activate

# Verify Python is from venv
which python   # Should show /path/to/app/venv/bin/python

Install Dependencies

# From project root with venv activated
pip install -r requirements.txt

# Example requirements.txt for Flask:
# Flask==2.3.0
# Gunicorn==20.1.0
# python-dotenv==1.0.0

Setup Gunicorn

# Install gunicorn in venv
pip install gunicorn

# Test locally (from project root)
gunicorn --bind 127.0.0.1:8000 app:app
# For Flask app named 'app' in app.py

Nginx Reverse Proxy

# In CloudPanel, go to Site → Reverse Proxy
# Add upstream:
upstream gunicorn {
    server 127.0.0.1:8000;
}

# Proxy requests:
location / {
    proxy_pass http://gunicorn;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

systemd Service File

# Create: /etc/systemd/system/myapp.service
[Unit]
Description=My Python App
After=network.target

[Service]
Type=notify
User=clpanel
WorkingDirectory=/home/clpanel/myapp
ExecStart=/home/clpanel/myapp/venv/bin/gunicorn \
    --workers 3 \
    --bind 127.0.0.1:8000 \
    app:app

Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

# Enable and start:
systemctl daemon-reload
systemctl enable myapp
systemctl start myapp
systemctl status myapp

Deploy and Restart

# Pull latest code from Git
cd /home/clpanel/myapp
git pull origin main

# Activate venv and update dependencies
source venv/bin/activate
pip install -r requirements.txt

# Restart Gunicorn
systemctl restart myapp

Troubleshooting

# Check if Gunicorn is running
systemctl status myapp

# View logs
journalctl -u myapp -n 50   # Last 50 lines
journalctl -u myapp -f       # Follow logs in real-time

# Test Nginx can reach Gunicorn
curl http://127.0.0.1:8000

# Check port 8000 is open
netstat -tlnp | grep 8000
Workers = CPU cores for Gunicorn

Set --workers to (CPU cores × 2) + 1. For a 2-core VPS, use 5 workers. This balances concurrency with memory usage.

Related: Python deployment | Node.js on CloudPanel | Git deployment | Gunicorn WSGI

Was this article helpful?

Need CloudPanel on a server?

Use CloudPanel on an UnderHost VPS or dedicated server for fast PHP app and WordPress hosting without a heavy panel stack.

Back to CloudPanel