ravexu
ravexu

Reputation: 665

How can I deploy FastAPI manually on a Ubuntu Server?

I have a very simple API (2 routes) which just has GET requests, and doesnt need any authentication or anything for now.

I want to know what is the best and appropariate way to deploy my API for production. I am unable to use docker, and would like to do it the server way.

So i have a few questions:

I am just a little confused on how to deploy this because one article says do this, another says do this.

Upvotes: 5

Views: 11907

Answers (2)

navule
navule

Reputation: 3624

To answer your Question:

How can I deploy FastAPI manually on a Ubuntu Server?

You can check out this video tutorial on how to Deploy FastAPI on Ubuntu

The deployment has the following architecture within a single Ubuntu VM.

enter image description here

As you take a look at the Architectural diagram above for FastAPI Deployment, it shows a single VM deployment.

Within the Ubuntu VM, there are two systemd services namely caddy.service and gunicorn.service up and running. The gunicorn.service runs the FastAPI application and the caddy.service exposes the FastAPI application running on Gunicorn as a reverse proxy with the help of uvicorn.workers.UvicornWorker worker class. In addition to this, our FastAPI communicates to PostgreSQL database server in an asynchronous fashion with the help of databases package that provides simple asyncio support for PostgreSQL database.

Upvotes: 1

Hossein Heydari
Hossein Heydari

Reputation: 1549

If for whatever reasons you don't like to use Docker-Ce, the best way is to create a systemd-service unit for your application so every time it goes down, systemd will try to restart it, then run it with servers like wgsi or gunicorn.

This link can help about systemd-services too:

https://blog.miguelgrinberg.com/post/running-a-flask-application-as-a-service-with-systemd

P.S note that the way you serve gunicorn isn't really related to docker or systemd-service, for both approaches you need to config gunicorn.

Upvotes: 4

Related Questions