DEV Community

Cover image for From Localhost to Live SaaS: Deploying My FastAPI App with Apache, SSL & JWT Auth
Bharath Kumar_30
Bharath Kumar_30

Posted on

From Localhost to Live SaaS: Deploying My FastAPI App with Apache, SSL & JWT Auth

Hey friends πŸ‘‹

Today I’m sharing my complete real-world deployment journey β€” from building a FastAPI project to making it live with:

  • JWT Authentication (Login/Register)
  • Landing Page + Dashboard UI
  • FastAPI Backend
  • Apache Reverse Proxy
  • HTTPS (SSL with Certbot)
  • VPS Hosting (Linux)

This is a step-by-step, copy-paste friendly guide β€” no confusion, just execution


Project Overview

My project includes:

  • βœ… Landing page
  • βœ… User Registration & Login
  • βœ… JWT Authentication
  • βœ… Dashboard (after login)
  • βœ… API-based backend (FastAPI)
  • βœ… Static + Templates (HTML/CSS/JS)

Step 1 β€” Setup Server

Install Python & pip:

sudo apt update
sudo apt install python3 python3-pip -y
Enter fullscreen mode Exit fullscreen mode

Step 2 β€” Upload Project

Navigate to your project folder:

cd ~/htdocs/soical-media-automation/automation_platform
Enter fullscreen mode Exit fullscreen mode

Step 3 β€” Install Dependencies

If you have requirements.txt:

pip3 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

If not:

pip3 install fastapi uvicorn python-dotenv
Enter fullscreen mode Exit fullscreen mode

Step 4 β€” Run FastAPI App

nohup python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > uvicorn.log 2>&1 &
Enter fullscreen mode Exit fullscreen mode

Check if running:

ps aux | grep uvicorn
Enter fullscreen mode Exit fullscreen mode

Step 5 β€” Setup Apache (Reverse Proxy)

Install Apache:

sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode

Enable required modules:

sudo a2enmod proxy
sudo a2enmod proxy_http
Enter fullscreen mode Exit fullscreen mode

Step 6 β€” Apache Config (Single Clean Config)

Open config:

sudo nano /etc/apache2/sites-available/001-automate.conf
Enter fullscreen mode Exit fullscreen mode

Paste:

<VirtualHost *:80>
    ServerName automated.soicalmedia.selfmade.one
    Redirect / https://automated.soicalmedia.selfmade.one/
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName automated.soicalmedia.selfmade.one

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/automated.soicalmedia.selfmade.one/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/automated.soicalmedia.selfmade.one/privkey.pem

    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Enter fullscreen mode Exit fullscreen mode

Step 7 β€” Clean Apache Sites

Disable default configs:

sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
sudo a2dissite 001-automate-le-ssl.conf
Enter fullscreen mode Exit fullscreen mode

Enable your config:

sudo a2ensite 001-automate.conf
sudo service apache2 restart
Enter fullscreen mode Exit fullscreen mode

Step 8 β€” Setup SSL (HTTPS)

Install Certbot:

sudo apt install certbot python3-certbot-apache -y
Enter fullscreen mode Exit fullscreen mode

Run:

sudo certbot --apache -d automated.soicalmedia.selfmade.one
Enter fullscreen mode Exit fullscreen mode

Choose:

  • Email β†’ your email
  • Agree β†’ Yes
  • Redirect β†’ Yes (HTTPS)

Step 9 β€” Create init.sh (Auto Run)

nano ~/init.sh
Enter fullscreen mode Exit fullscreen mode

Paste:

#!/bin/bash

cd /home/mr.potter/htdocs/soical-media-automation/automation_platform

nohup python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > uvicorn.log 2>&1 &
Enter fullscreen mode Exit fullscreen mode

Run:

chmod +x init.sh
./init.sh
Enter fullscreen mode Exit fullscreen mode

Step 10 β€” JWT Authentication (Concept)

My app includes:

  • User registration
  • Login system
  • JWT token generation
  • Protected dashboard

Example flow:

from fastapi import Depends
from fastapi.security import OAuth2PasswordBearer

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login")

@app.get("/dashboard")
def dashboard(token: str = Depends(oauth2_scheme)):
    return {"message": "Welcome to dashboard"}
Enter fullscreen mode Exit fullscreen mode

Frontend Structure

templates/
    index.html
    login.html
    register.html
    dashboard.html

static/
    css/
    js/
Enter fullscreen mode Exit fullscreen mode

Common Issues I Faced (And Fixes)

Too Many Redirects

Cause: Multiple Apache configs
Fix: Use single config only


requirements.txt not found

Wrong folder
Fix: cd into correct directory


Permission denied

Fix:

sudo chown mr.potter:mr.potter filename
Enter fullscreen mode Exit fullscreen mode

systemctl not working

Use:

sudo service apache2 restart
Enter fullscreen mode Exit fullscreen mode

Final Result

βœ” Live SaaS App
βœ” Secure HTTPS
βœ” Login/Register system
βœ” Dashboard
βœ” API backend


Final Thoughts

This wasn’t just deployment β€” it was:

  • DevOps basics
  • Backend engineering
  • Real production setup

If you’re building something similar β€” don’t stop at localhost.
Deploy it. Break it. Fix it. Learn it


Let’s Connect

If you’re building something cool or stuck in deployment, feel free to reach out

Happy coding

Top comments (0)