Python FastAPI Tutorial (Part 18): Deploy to a VPS - Security, Nginx, SSL, and Custom Domain

Corey Schafer
Corey SchaferApr 19, 2026

Why It Matters

Deploying FastAPI on a VPS teaches fundamental, transferable server‑management skills, ensuring applications are secure, observable, and ready for real‑world traffic.

Key Takeaways

  • Add a lightweight health‑check endpoint for database connectivity
  • Push code to GitHub, ensuring .gitignore hides secrets
  • Create a VPS, update OS, and add a non‑root user
  • Configure Nginx, obtain free SSL via Let’s Encrypt, link custom domain
  • Harden server: firewall, sudo privileges, regular updates

Summary

The tutorial walks viewers through deploying a production‑ready FastAPI blog to a virtual private server. After adding a simple health‑check route that verifies database access, the instructor pushes the entire codebase to a public GitHub repository, emphasizing the importance of a .gitignore to keep credentials safe.

Next, a new VPS on Linode is provisioned with Ubuntu 24.04 LTS, followed by system updates, creation of a non‑root user with sudo rights, and basic security hardening. The guide then clones the GitHub repo, installs dependencies, and sets up Gunicorn and Nginx to serve the FastAPI app, securing traffic with a free Let’s Encrypt SSL certificate tied to a custom domain (myawesomeapp.com).

Key examples include the health‑check implementation that returns a 503 on database failure, and the step‑by‑step Nginx configuration that proxies requests to Gunicorn while enforcing HTTPS. The instructor also demonstrates using SSH keys, configuring the firewall, and verifying the deployment via the health endpoint and API docs.

By the end, viewers have a fully functional, HTTPS‑secured FastAPI service on a low‑cost VPS, equipped with monitoring hooks and a hardened security baseline that can be adapted to any cloud provider.

Original Description

In this video, we'll be learning how to deploy our FastAPI application to a VPS (Virtual Private Server) so that it's live and accessible on the internet. We'll walk through the entire process, starting with a fresh Ubuntu server and hardening it with SSH key authentication, a firewall, and brute force protection. From there, we'll set up Nginx as a reverse proxy, enable HTTPS with a free SSL certificate from Let's Encrypt, point a custom domain to our application, and use systemd to manage the app as a service so it starts on boot and restarts automatically if it crashes. By the end of this video, you'll have a secure, production-ready FastAPI deployment with a real domain name. Let's get started...
Timestamps:
Skip to 42:11 if your server is already secure
Skip to 59:05 for the FastAPI-specific deployment steps
The code from this video can be found here:
Full FastAPI Course:
Linode (with Referral):
NameCheap (with Referral):
WSL (Windows):
Git for Windows:
✅ Support My Channel Through Patreon:
✅ Become a Channel Member:
✅ One-Time Contribution Through PayPal:
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
✅ Equipment I Use and Books I Recommend:
▶️ You Can Find Me On:
My Website - http://coreyms.com/
#Python #FastAPI

Comments

Want to join the conversation?

Loading comments...