AdminsForum

CloudPanel Node.js & Python Guides

Guide How to Deploy a Python App (Django or Flask) on CloudPanel with uWSGI

Started by JAY 0 replies 98 views
1JAY
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#1
How to deploy a Python app (Django or Flask) on CloudPanel with uWSGI

CloudPanel has a Python site type for Django, Flask, FastAPI and other Python web apps. It creates the domain, a site user and an Nginx vhost that forwards requests to an App Port. For production, CloudPanel's own documentation runs the app with uWSGI, which is already installed with CloudPanel. This guide follows that setup.

Step 1: Create the Python site
  1. Go to Sites > Add Site > Create a Python Site.
  2. Enter the Domain Name, choose the Python Version and set the App Port, for example 8090.
  3. Set the Site User and password, then click Create.
Note the site user and App Port; you need both below.

Step 2: Upload the app and create a virtual environment
Log in over SSH as the site user and put your project in the site folder:
Code:
ssh site-user@YOUR_SERVER_IP cd ~/htdocs rm -rf www.example.com git clone https://github.com/your-name/your-app.git www.example.com cd www.example.com python3 -m venv venv source venv/bin/activate pip install -r requirements.txt deactivate
For Django, also set
Code:
ALLOWED_HOSTS
to your domain, set
Code:
DEBUG = False
, and run
Code:
python manage.py migrate
and
Code:
python manage.py collectstatic
inside the virtual environment.

Find your app's WSGI entry point. For Django it's
Code:
yourproject/wsgi.py
. For Flask, create a
Code:
wsgi.py
in the project root:
Code:
from app import app as application

Step 3: Create the uWSGI config (as root)
Log in as root and create a config file for the site:
Code:
cd /etc/uwsgi/apps-enabled/ nano www.example.com.uwsgi.ini
Paste this, then change the paths, the port and the site user to match your site:
Code:
[uwsgi] plugins = python3 master = true protocol = uwsgi socket = 127.0.0.1:8090 wsgi-file = /home/site-user/htdocs/www.example.com/yourproject/wsgi.py virtualenv = /home/site-user/htdocs/www.example.com/venv chdir = /home/site-user/htdocs/www.example.com buffer-size = 8192 reload-on-rss = 250 workers = 4 enable-threads = true close-on-exec = true umask = 0022 uid = site-user gid = site-user ignore-sigpipe = true ignore-write-errors = true disable-write-exception = true
The socket port must be the same as the App Port from Step 1, and uid/gid must be the site user so the app never runs as root.

Step 4: Point the Nginx vhost to uWSGI
In CloudPanel, open the site and go to the Vhost tab. The default vhost uses
Code:
proxy_pass
, which suits a development server. For uWSGI, change the
Code:
location /
block to:
Code:
location / { include uwsgi_params; uwsgi_read_timeout 3600; uwsgi_pass 127.0.0.1:{{app_port}}; }
Keep
Code:
{{app_port}}
as it is; CloudPanel fills in the site's App Port. Click Save.

To let Nginx serve Django's static files directly, add a block like this above it (adjust the path to your STATIC_ROOT):
Code:
location /static/ { alias /home/site-user/htdocs/www.example.com/static/; }

Step 5: Restart uWSGI and test
Code:
systemctl restart uwsgi ss -tulpn | grep uwsgi
You should see uWSGI listening on
Code:
127.0.0.1:8090
. Open your domain in the browser. Then reboot the server once to confirm the app starts on its own.

After code changes, restart uWSGI again with
Code:
systemctl restart uwsgi
.

Step 6: Add free SSL
Go to SSL/TLS > Actions > New Let's Encrypt Certificate for the site. Guide: How to install free SSL in CloudPanel.

Troubleshooting
  • 502 Bad Gateway: uWSGI isn't running or uses another port. Check
    Code:
    systemctl status uwsgi
    and compare the socket port with the App Port.
  • Errors after a restart: read the uWSGI logs in
    Code:
    /var/log/uwsgi/app/
    .
  • "ModuleNotFoundError": the virtualenv path is wrong or packages were installed outside it.
  • Django "DisallowedHost": add your domain to ALLOWED_HOSTS.
  • CSS and images missing in Django: run collectstatic and check the /static/ location block.

Sources (checked October 2026): CloudPanel: Python deployment with uWSGI

Not sure which site type to choose? See What can you host on CloudPanel?
Reply
Possibly Related Threads…matched by title
Replies:0Views:90
Replies:0Views:89

Users browsing this thread: 1 Guest(s)
Forum Jump: