Geeky Shows
28 Jul 2025
Deploy FastAPI Async App on Hostinger VPS with Nginx, Gunicorn, Uvicorn & HTTPS
If you're a Python backend developer exploring FastAPI, you've probably enjoyed its speed and simplicity. But deploying a FastAPI app for production can seem overwhelming — especially when you want scalability, security, and performance.
In this guide, I’ll walk you through deploying your FastAPI async app on a Hostinger VPS using Ubuntu, Gunicorn + Uvicorn, Nginx, and Let's Encrypt SSL. This setup ensures your API is secure, production-ready, and blazing fast.
Why Hostinger?
Before we dive into the technicals — I highly recommend using a Hostinger VPS for your deployment needs. It’s affordable, developer-friendly, and comes with full root access.
Step 1: Install System Packages
SSH into your VPS and install necessary packages:
sudo apt updatesudo apt install nginx python3 python3.12-venv git
Step 2: Setup SSH Deploy Key for GitHub
Generate and configure an SSH key so your VPS can pull private GitHub repos:
ssh-keygen -f /home/raj/.ssh/ch124_ed25519 -t ed25519 -C "ch124repo"cat ~/.ssh/ch124_ed25519.pub
Add Key to GitHub
- Go to GitHub → Repo Settings → Deploy Keys → Add Key
- Paste your public key content
Configure SSH for GitHub
nano ~/.ssh/config
Add:
Host ch124_project HostName github.com User git IdentityFile ~/.ssh/ch124_ed25519 IdentitiesOnly yes
Test:
ssh -T git@ch124_project
Step 3: Clone Your FastAPI Project
git clone git@ch124_project:rajeshrajkr4/ch124.gitcd ch124python3 -m venv venvsource venv/bin/activatepip install -r requirements.txtpip install gunicorn
Start Gunicorn manually to test:
gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
Step 4: Setup Gunicorn as a Systemd Service
Create a service file:
sudo nano /etc/systemd/system/ch124.service
Paste:
[Unit]Description=Gunicorn instance to serve ch124 FastAPI AppAfter=network.target
[Service]User=rajGroup=www-dataWorkingDirectory=/home/raj/ch124Environment="PATH=/home/raj/ch124/venv/bin"ExecStart=/home/raj/ch124/venv/bin/gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:8000
[Install]WantedBy=multi-user.target
Start and enable the service:
sudo systemctl daemon-reexecsudo systemctl daemon-reloadsudo systemctl start ch124sudo systemctl enable ch124
To check logs:
sudo journalctl -u ch124 -f
Step 5: Configure Nginx as a Reverse Proxy
sudo nano /etc/nginx/sites-available/ch124
Paste:
# Redirect www to non-wwwserver { listen 80; server_name www.javascriptguru.in; return 301 $scheme://javascriptguru.in$request_uri;}
# Main Appserver { listen 80; server_name javascriptguru.in;
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; }}
Enable Nginx site:
sudo ln -s /etc/nginx/sites-available/ch124 /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginx
Step 6: Deploy Code Changes
Whenever you push changes to GitHub:
cd ~/ch124git pullsudo systemctl restart ch124.service
Step 7: Add HTTPS with CertbotInstall and configure Certbot for free SSL:
sudo apt install certbot python3-certbot-nginxsudo certbot --nginx -d javascriptguru.in -d www.javascriptguru.in