You’ve built a Flask or FastAPI app and it runs on your laptop. Now you want it online, on a server you control, with your own domain and HTTPS. This guide shows you how to deploy Python application on VPS hosting, step by step, using Ubuntu 24.04, Gunicorn or Uvicorn, Nginx and systemd.
Every command is explained, so you can follow along even if this is your first Linux server. By the end, your app will start on boot, restart itself if it crashes and serve visitors over HTTPS.
What you’ll set up in this guide
- A secure SSH login and a non-root user with sudo rights
- Python, a virtual environment and your project’s dependencies
- A production server: Gunicorn for Flask or Uvicorn for FastAPI
- A systemd service that keeps the app running
- Nginx as a reverse proxy, a domain and a free HTTPS certificate
- A firewall, safer SSH settings and a backup routine
What is a VPS, and why use one for Python apps?
A VPS (virtual private server) is a virtual machine on a physical server, with its own share of CPU, RAM and storage, its own operating system and its own IP address. You get root access, so you can install any software Linux runs.
That freedom is why developers choose Python VPS hosting. Shared web hosting is built for PHP websites, and it usually won’t let you run long-lived processes, choose your Python version or install system packages. On a VPS, you can:
- Run long-lived processes such as a web app, an API, a Telegram or Discord bot, or a background worker
- Pick your Python version and install any package from PyPI
- Configure Nginx, databases, Redis or Docker the way your project needs
- Get a dedicated IPv4 address and predictable resources that other customers can’t use up
The trade-off is responsibility. On an unmanaged VPS, you install updates, configure the firewall and keep backups yourself. This guide covers each of those tasks. If you’re still choosing a server, read our guide to VPS hosting in India first.
What you need before you start
| You need | Why |
|---|---|
| A Linux VPS with root SSH access | This guide uses Ubuntu 24.04. Notes for Debian 12 and AlmaLinux 9 are included where commands differ. |
| An SSH client | Terminal on macOS and Linux, or PowerShell on Windows 10 and 11, which includes OpenSSH. |
| Your Python project | Ideally in a Git repository, with a requirements.txt file listing its dependencies. |
| A domain name (optional) | You can test with the server’s IP address, but you need a domain for HTTPS. |
| About an hour | Most of it is reading. The commands themselves take a few minutes. |
In the examples, 203.0.113.24 stands for your server’s IP address, example.com for your domain and myapp for your project. Replace them with your own values.
How to deploy Python application on VPS: the workflow
Python app deployment follows the same path whatever framework you use. You connect to the server, prepare it, upload your code, install dependencies, run the app with a production server, keep it running with systemd, put Nginx in front of it, then add a domain, HTTPS, a firewall and backups.

Step 1: Connect to your Linux VPS with SSH
SSH (Secure Shell) gives you an encrypted command line on the server. Logging in with an SSH key is safer than a password, so create a key pair on your own computer if you don’t have one yet:
ssh-keygen -t ed25519 -C "you@example.com"
This creates a private key (~/.ssh/id_ed25519), which never leaves your computer, and a public key (~/.ssh/id_ed25519.pub), which you add to the server. Press Enter to accept the default location, and set a passphrase for extra protection.
Many VPS providers ask for your public key when the server is created. On Nomos, you add it right after payment, while choosing the operating system. Print the public key so you can copy it:
cat ~/.ssh/id_ed25519.pub
When the server is ready, connect as root:
ssh root@203.0.113.24
The first time you connect, SSH shows the server’s fingerprint and asks whether to trust it. Type yes. You’re now at a root prompt on your server.
Create a non-root user
Root can change anything, so a typo can do real damage. Create a regular user for daily work and deployments, and give it sudo rights:
adduser deploy
usermod -aG sudo deploy
adduser creates the user and asks for a password, which you’ll use with sudo. usermod -aG sudo adds the user to the sudo group. Then copy your SSH key to the new user, so you can log in as deploy with the same key:
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy
Open a new terminal window and check that this works before you close the root session:
ssh deploy@203.0.113.24
On AlmaLinux 9, the admin group is called wheel, so use usermod -aG wheel deploy, and set the password with passwd deploy.
Step 2: Prepare the Linux server for Python
Update the package lists and install the latest security fixes first:
sudo apt update
sudo apt upgrade -y
apt update downloads the latest list of available packages, and apt upgrade -y installs the updates without asking for confirmation. If the kernel was updated, reboot with sudo reboot and log back in.
Now install everything this guide needs:
sudo apt install -y python3 python3-venv python3-pip git nginx
python3: the Python interpreter. Ubuntu 24.04 ships Python 3.12.python3-venv: lets you create virtual environments.python3-pip: the Python package installer.git: to clone and update your code.nginx: the web server you’ll use as a reverse proxy.
Check the Python version:
python3 --version
If your project needs a different Python version, install it before you continue, because the virtual environment uses whichever interpreter creates it. On AlmaLinux 9, use sudo dnf install -y python3 python3-pip git nginx; the venv module is included with Python there.
Step 3: Upload or clone your Python project
Keep your app in its own folder, owned by the deploy user. This guide uses /srv/myapp:
sudo mkdir -p /srv/myapp
sudo chown deploy:deploy /srv/myapp
mkdir -p creates the folder, and chown makes deploy its owner, so you don’t need sudo to work inside it.
Option A: clone from Git (recommended)
git clone https://github.com/your-username/myapp.git /srv/myapp
For a private repository, create a separate SSH key on the server and add it to your Git host as a read-only deploy key. Git also makes updates easy later: you run git pull instead of copying files again.
Option B: copy files from your computer
Run this on your own computer, from the folder that contains your project:
rsync -avz --exclude "venv" --exclude ".git" --exclude "__pycache__" ./ deploy@203.0.113.24:/srv/myapp/
rsync copies only what has changed, -avz keeps permissions, lists each file and compresses the transfer, and --exclude skips folders that don’t belong on the server. Never copy your local virtual environment; you’ll create a fresh one on the server.
No project yet? Use this Flask example
To follow along with a minimal app, create /srv/myapp/app.py with nano /srv/myapp/app.py and paste in:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from my Python app on a VPS!"
Save with Ctrl+O and Enter, then exit with Ctrl+X. The app variable is what Gunicorn will load later.
Step 4: Create a virtual environment and install dependencies
A virtual environment is a private folder of Python packages for one project. It keeps your app’s dependencies separate from the system Python that Ubuntu relies on, and it lets two apps on the same server use different package versions.
cd /srv/myapp
python3 -m venv venv
source venv/bin/activate
python3 -m venv venv creates the environment in a folder called venv. source venv/bin/activate switches your shell to it, and your prompt now starts with (venv). Next, upgrade pip and install your dependencies:
pip install --upgrade pip
pip install -r requirements.txt
If you’re using the Flask example, there’s no requirements file yet, so install the packages directly and save the list:
pip install flask gunicorn
pip freeze > requirements.txt
If you see error: externally-managed-environment, pip is trying to install into the system Python, which Ubuntu 24.04 and Debian 12 block. Activate the virtual environment and run the command again.
Step 5: Run the app with a production server
flask run and uvicorn --reload are development servers. They’re fine on your laptop, but they aren’t built for real traffic. In production, use a dedicated application server:
| Framework | Interface | Production server |
|---|---|---|
| Flask, Django | WSGI | Gunicorn |
| FastAPI, Starlette | ASGI | Uvicorn (with several workers) |
Deploy a Flask application on VPS with Gunicorn
Inside the activated virtual environment, start Gunicorn:
gunicorn --workers 3 --bind 127.0.0.1:8000 app:app
app:app means “the app object inside app.py”. --bind 127.0.0.1:8000 listens only on the server itself, so the app isn’t exposed to the internet directly; Nginx will forward traffic to it. --workers 3 runs three processes to handle requests in parallel. The Gunicorn documentation suggests (2 × CPU cores) + 1 workers as a starting point.
Open a second SSH session and check that the app answers:
curl http://127.0.0.1:8000
You should see Hello from my Python app on a VPS!. Stop Gunicorn with Ctrl+C. You’ll run it with systemd in the next step.
Deploy FastAPI on VPS with Uvicorn
For a FastAPI project, install FastAPI and Uvicorn in the virtual environment:
pip install fastapi uvicorn
pip freeze > requirements.txt
A minimal main.py looks like this:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello from FastAPI on a VPS"}
Run it with several worker processes, bound to localhost:
uvicorn main:app --host 127.0.0.1 --port 8000 --workers 2
Test it with curl http://127.0.0.1:8000 from a second session. The rest of this guide works the same for FastAPI: wherever the Flask example uses the Gunicorn command, use this Uvicorn command instead. See the FastAPI deployment docs for more options.
Step 6: Keep the app running with systemd
If you close your SSH session, the app stops. systemd, the service manager built into Ubuntu, Debian and AlmaLinux, solves that: it starts your app at boot, restarts it if it crashes and collects its logs. Create a service file:
sudo nano /etc/systemd/system/myapp.service
Paste in this configuration:
[Unit]
Description=Gunicorn for myapp
After=network.target
[Service]
User=deploy
WorkingDirectory=/srv/myapp
EnvironmentFile=-/srv/myapp/.env
ExecStart=/srv/myapp/venv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 app:app
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
User: runs the app asdeploy, not root.WorkingDirectory: the folder the app starts in.EnvironmentFile: loads settings and secrets from/srv/myapp/.env, oneKEY=valueper line. The leading-means the service still starts if the file doesn’t exist yet.ExecStart: the full path to Gunicorn inside your virtual environment, so you don’t need to activate it. For FastAPI, use/srv/myapp/venv/bin/uvicorn main:app --host 127.0.0.1 --port 8000 --workers 2.Restart=always: restarts the app if it stops, after a 5-second pause.
Load the new file, then start the service and enable it at boot:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
daemon-reload tells systemd to read the new file, enable --now starts the service and enables it at boot in one command, and status should show active (running). To follow the app’s logs live, use:
sudo journalctl -u myapp -f
Keep secrets such as database passwords and API keys in .env, never in Git, and make the file readable only by its owner with chmod 600 /srv/myapp/.env.
Step 7: Configure Nginx as a reverse proxy
Your app now listens on 127.0.0.1:8000, which only the server can reach. Nginx sits in front of it: it accepts visitors on ports 80 and 443, handles HTTPS and slow connections, serves static files quickly and passes each request to your app. This is called a reverse proxy.

Create an Nginx configuration file for your site:
sudo nano /etc/nginx/sites-available/myapp
Paste in this server block, replacing example.com with your domain or your server’s IP address:
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:8000;
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;
}
}
proxy_pass forwards requests to your app. The proxy_set_header lines pass on the original host name, the visitor’s IP address and whether they used HTTPS, which your app would otherwise not see. The Nginx proxy module documentation explains each directive.
Enable the site, remove the default welcome page, test the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
ln -s creates a link that turns the site on, and nginx -t checks the configuration for mistakes before you apply it. Always run it before reloading. Now open http://203.0.113.24 in your browser, and you should see your app.
Tell your app it’s behind a proxy
Because requests now arrive from Nginx, a Flask app needs to trust the forwarded headers so that generated URLs and redirects use the right scheme and host. Add Werkzeug’s ProxyFix middleware to app.py:
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1)
Uvicorn already reads these headers from proxies on 127.0.0.1 by default, so a FastAPI app on the same server needs no change.
Serve static files with Nginx (optional)
If your app has a static folder of CSS, JavaScript and images, let Nginx serve it directly. Add this block inside the server block, above location /:
location /static/ {
alias /srv/myapp/static/;
}
Nginx needs permission to read that folder. If you get a 403 error, check that every folder in the path can be entered by other users, for example with chmod 755 /srv/myapp.
On AlmaLinux 9, put the server block in /etc/nginx/conf.d/myapp.conf instead, and allow Nginx to connect to your app under SELinux with sudo setsebool -P httpd_can_network_connect 1. Without it, you’ll see a 502 error.
Step 8: Connect a domain and set up HTTPS
Point your domain at the VPS
In the DNS settings wherever your domain is managed, add two records. If you don’t have a domain yet, you can register one with Nomos or any registrar.
| Type | Name | Value |
|---|---|---|
| A | @ | 203.0.113.24 |
| A | www | 203.0.113.24 |
The @ record covers example.com and the www record covers www.example.com. DNS changes usually take effect within minutes, but can take up to 48 hours. Check from your computer:
nslookup example.com
When the answer shows your server’s IP address, open http://example.com. You should see your app.
Get a free HTTPS certificate with Certbot
Certbot gets a free certificate from Let’s Encrypt and updates your Nginx configuration to use it. Ports 80 and 443 must be open, which you’ll make sure of in the next step. On Ubuntu 24.04 and Debian 12, install it with apt:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Certbot asks for an email address for expiry notices, checks that you control the domain and installs the certificate. Certificates last 90 days, and the package sets up automatic renewal. Test that renewal works:
sudo certbot renew --dry-run
Your app is now available at https://example.com. Certbot’s site has instructions for other systems, including AlmaLinux 9.
Step 9: Secure the server and configure the firewall
A new server on a public IP address gets automated login attempts within hours. These basics close the most common gaps.
Turn on the UFW firewall
UFW (Uncomplicated Firewall) comes with Ubuntu. Allow SSH first, so you don’t lock yourself out, then allow web traffic and switch the firewall on:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status
Nginx Full opens ports 80 and 443. Port 8000 stays closed, because the app only listens on localhost. On Debian 12, install UFW first with sudo apt install ufw. On AlmaLinux 9, use firewalld instead:
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload
Harden SSH
Once you can log in as deploy with your key, turn off password logins and direct root logins. Edit /etc/ssh/sshd_config and set:
PasswordAuthentication no
PermitRootLogin no
Files in /etc/ssh/sshd_config.d/ can override these settings, so check them too. Then test the configuration and restart SSH, keeping your current session open until a new login works:
sudo sshd -t
sudo systemctl restart ssh
On AlmaLinux 9, the service is called sshd.
Keep the system updated
Unattended upgrades install security updates automatically on Ubuntu and Debian:
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
Also update your Python packages from time to time, test the app and restart the service. Tools such as pip list --outdated show what has newer versions.
Step 10: Back up your VPS yourself
On an unmanaged VPS, backups are your job. A failed upgrade, a deleted folder or a broken database can happen to anyone, and a backup stored on the same server disappears with it. Keep copies somewhere else.
Your code is already safe in Git. Back up everything that isn’t:
.envand any other secrets- Your database, exported with
pg_dumpfor PostgreSQL ormysqldumpfor MySQL - User uploads and any files your app writes
/etc/nginx/sites-available/myappand/etc/systemd/system/myapp.service
A simple approach is a dated archive on the server, copied to your own computer or another server:
sudo tar -czf /home/deploy/backup-$(date +%F).tar.gz /srv/myapp/.env /etc/nginx/sites-available/myapp /etc/systemd/system/myapp.service
sudo chown deploy:deploy /home/deploy/backup-*.tar.gz
tar -czf packs the files into one compressed archive, and $(date +%F) adds today’s date to its name. Then, from your own computer:
rsync -avz deploy@203.0.113.24:/home/deploy/backup-*.tar.gz ./vps-backups/
Once this works, put the commands in a script and schedule it with cron, and add your database dump to the same script. Follow the 3-2-1 rule if the data matters: three copies, on two kinds of storage, with one away from the server. Most important, restore a backup now and then, so you know it works.
How to deploy updates
After the first setup, releasing a new version takes a minute:
cd /srv/myapp
git pull
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart myapp
git pull fetches the new code, pip install adds any new dependencies, and restarting the service loads the new version. Check the logs with sudo journalctl -u myapp -n 50. If something breaks, check out the previous commit with Git and restart the service.

Common deployment errors and how to fix them
Most problems show up in one of three places: sudo systemctl status myapp, sudo journalctl -u myapp -n 50 and /var/log/nginx/error.log. Start there.
502 Bad Gateway
Cause: The app isn’t running, or Nginx and the app use different ports. Fix: Check sudo systemctl status myapp, read the logs and run curl http://127.0.0.1:8000. Make sure proxy_pass and --bind use the same port.
Permission denied (publickey)
Cause: The server doesn’t have your public key, or you’re using the wrong user name. Fix: Check that you’re connecting as the right user, and run ssh -v with your usual login to see which key is offered.
error: externally-managed-environment
Cause: pip is trying to install into the system Python. Fix: Activate the virtual environment with source venv/bin/activate, then run the command again.
ModuleNotFoundError
Cause: A package is missing, or systemd isn’t using your virtual environment. Fix: Run pip install -r requirements.txt inside the venv, and check that ExecStart points to the venv/bin folder.
Address already in use
Cause: Another process is using port 8000, often an old Gunicorn you started by hand. Fix: Find it with sudo ss -tlnp | grep 8000, stop it, then restart the service.
nginx -t fails
Cause: A typo in the server block, such as a missing semicolon or brace. Fix: Read the line number in the error, fix the file and test again before reloading.
Certbot fails
Cause: DNS doesn’t point to the server yet, or port 80 is blocked. Fix: Check the domain with nslookup, and check that the firewall allows Nginx Full.
Site loads by IP but not by domain
Cause: DNS hasn’t updated yet, or server_name doesn’t match your domain. Fix: Wait for DNS to update, and check server_name in your Nginx file.
Code changes don’t appear
Cause: The service is still running the old code. Fix: Run sudo systemctl restart myapp after every update.
If the service keeps restarting, run the ExecStart command by hand as the deploy user, inside the virtual environment. You’ll see the full Python error in your terminal.
Python VPS deployment checklist
- ✅ You log in as a sudo user with an SSH key, not as root with a password
- ✅ System packages are updated, and unattended upgrades are on
- ✅ The app runs in its own virtual environment, with dependencies in
requirements.txt - ✅ Gunicorn or Uvicorn listens on
127.0.0.1, not on a public address - ✅ A systemd service starts the app at boot and restarts it on failure
- ✅ Nginx proxies to the app, and
nginx -tpasses - ✅ DNS points to the server, and HTTPS works with automatic renewal
- ✅ The firewall allows only SSH, HTTP and HTTPS
- ✅ Secrets live in
.envwithchmod 600, not in Git - ✅ Backups are copied off the server, and you’ve tested a restore
Nomos VPS: a Linux VPS server for Python
Nomos is the company behind this blog, so this section describes our own product. Nomos VPS gives you an unmanaged Linux server, which is everything this guide needs to host a Python application on a Linux server:
- Full root access over SSH
- Ubuntu 24.04, Debian 12 or AlmaLinux 9
- NVMe storage and a dedicated IPv4 address on every plan
- Servers in India
- Billing in rupees, month to month with no lock-in or on 12 or 24 months, with an invoice for every payment
- Reboots, reinstalls, SSH keys and reverse DNS on request
After payment, you choose the operating system, add your SSH key and name the server. Our team then builds it, usually within a few hours during support hours (Monday to Saturday, 10:00 to 19:00 IST), and emails you when it’s ready.
| Plan | Resources (transfer is per month) | 24 months | 12 months | Monthly |
|---|---|---|---|---|
| VPS 1 | 1 vCPU, 4 GB RAM, 50 GB NVMe, 4 TB transfer | ₹479/mo | ₹599/mo | ₹799/mo |
| VPS 2 | 2 vCPU, 8 GB RAM, 100 GB NVMe, 8 TB transfer | ₹619/mo | ₹799/mo | ₹1,039/mo |
| VPS 4 | 4 vCPU, 16 GB RAM, 200 GB NVMe, 16 TB transfer | ₹879/mo | ₹1,083/mo | ₹1,999/mo |
| VPS 8 | 8 vCPU, 32 GB RAM, 400 GB NVMe, 32 TB transfer | ₹1,759/mo | ₹2,169/mo | ₹3,999/mo |
Prices exclude tax. VPS 1 suits a bot, an API or your first app, and VPS 2 suits production apps with a database.
Before you choose, know what an unmanaged VPS means. You install and update the software yourself, including Python, Nginx and your app’s dependencies, and you manage the firewall and your backups. Automated server backups aren’t included at launch, so follow Step 10. If you only need a website, web hosting is cheaper, and we look after the web server and SSL for you.
Frequently asked questions
What is the easiest way to deploy a Python application on a VPS?
Use the setup in this guide: a virtual environment for dependencies, Gunicorn or Uvicorn as the application server, systemd to keep it running and Nginx as a reverse proxy with a Certbot certificate. It works for most Flask, Django and FastAPI apps.
Should I use Gunicorn or Uvicorn?
Use Gunicorn for WSGI frameworks such as Flask and Django. Use Uvicorn for ASGI frameworks such as FastAPI, with the --workers option to run several processes.
Do I need Nginx if Gunicorn or Uvicorn can serve HTTP?
Yes, for a public site. Nginx handles HTTPS, slow clients and static files much better, and it lets your app listen only on localhost, which is safer.
How much RAM does a Python app need on a VPS?
It depends on the app, the number of workers and whether a database runs on the same server. Small Flask or FastAPI apps use little memory. Check real usage with free -h and add capacity when you need it.
Is Nomos VPS managed?
No. You get root access and run the software yourself, including updates, firewall rules and backups of your data. Nomos keeps the server reachable and handles reboots, reinstalls and reverse DNS when you ask.
Does Nomos back up my VPS?
Not at launch. Keep copies of anything important somewhere else, as described in the backup step of this guide.
Can I use Docker instead?
Yes. You have root access, so you can install Docker and run your app in containers. The same ideas still apply: a reverse proxy in front, HTTPS, a firewall and off-server backups.
Your Python app is live
You’ve now seen the whole path to deploy Python application on VPS hosting: SSH keys, a clean server, a virtual environment, Gunicorn or Uvicorn, systemd, Nginx, HTTPS, a firewall and backups. Save the checklist above, and you can repeat the process for every new project in under an hour.
Need a server to try it on? Compare Nomos VPS plans, from ₹479 a month plus tax, with root access and Ubuntu 24.04 ready for your first deployment.
