This is a work in progress. DO NOT USE THIS IN REAL PRODUCTION.
This is meant to get up and running asap on a cheap box.
This script automates the deployment of a FastAPI application on a Ubuntu server. It sets up the environment, installs necessary packages, configures Nginx as a reverse proxy, and creates a systemd service to manage the application.
- Ubuntu server (tested on Ubuntu 20.04 LTS)
- Sudo access
-
Update and Install Packages:
- Updates the package list
- Installs Python3, pip, Nginx, and UFW
-
Setup Virtual Environment:
- Creates a Python virtual environment
- Installs FastAPI and Uvicorn
-
Create FastAPI Application:
- Generates a simple FastAPI application with two endpoints
-
Configure Systemd Service:
- Creates a systemd service file for the FastAPI application
- Enables and starts the service
-
Configure Nginx:
- Sets up Nginx as a reverse proxy
- Enables gzip compression
-
Configure Firewall:
- Sets up UFW to allow SSH and HTTP traffic
clone the repo
-
Run the following command in the terminal:
chmod +x deploy_fastapi.sh
-
Run the script: Execute the script with sudo privileges:
sudo ./deploy_fastapi.sh
-
Check the output:
- The script will display the server's IP address where the application is accessible
- It will also provide instructions on how to check the application logs
- The nuke script removes the fastapi install
- Access your FastAPI application by navigating to
http://your_server_ip
- You can check the application logs using:
sudo journalctl -u myfastapiapp -f
If you encounter any issues:
- Check the systemd service status:
sudo systemctl status myfastapiapp
- Review the Nginx configuration:
sudo nginx -t
- Ensure the firewall is configured correctly:
sudo ufw status
- Modify the
main.py
file to change the FastAPI application - Adjust the Nginx configuration in the script for custom domain setup
- Modify the systemd service file to change resource limits or other parameters