Member-only story

How to deploy FastAPI with Nginx and Supervisor

Travis Luong
2 min readNov 27, 2021

--

In this tutorial, I will show you how to deploy a FastAPI app with Nginx and Supervisor.

First, launch a compute instance with a cloud platform of your choice. I will be using Ubuntu version 20.04 along with the default python version 3.8 and default ubuntu user.

Update packages.

sudo apt-get update

Install pip, venv, and nginx.

sudo apt-get -y install python3-pip python3-venv nginx

If you go to your IP address, you should see the welcome to nginx page.

Create a directory for the app.

mkdir hello_world
cd hello_world

Create and activate the virtualenv.

python3 -m venv venv
. venv/bin/activate

Install fastapi, uvicorn, and gunicorn.

pip install fastapi "uvicorn[standard]" gunicorn

Create the main.py file.

nano main.py

Paste the following code and save the file.

from fastapi import FastAPIapp = FastAPI()@app.get("/")
def read_root():
return {"Hello": "World"}

--

--

Responses (2)