Skip to content

Simple-Student-Projects/Ngnix-Demo-with-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ngnix Demo with Python / FastAPI


Intro

This project demonstrates a dummy FastAPI app that serves a cat picture, with Nginx configured as a reverse proxy and static file server.


Overview

We use Docker Compose v3.9 to orchestrate two containers:

  1. FastAPI App: Handles API requests and serves templates.
  2. Nginx: Acts as a reverse proxy for the FastAPI app and serves static files directly. (in front of FastAPI)

How to? Explained in details.

  1. In docker-compose.yml we:
    • Defined two services in docker-compose.yml: app (FastAPI app) and nginx.
    • Encapsulated the ports of app in docker-compose.yml
    • Mounted the static folder of app for nginx.
  2. Created nginx.conf file, with using the default image of Nginx.
    • Mounted the volume of static folder of app into nginx container, as well as nginx.conf file.

P.S. Why Mount static Twice?

As FastAPI doesn't have a command to consolidate static files into a single directory, like Django, here we mounted static folder twice: once for FastAPI app, then linking it to Nginx's container.

In frameworks with that feature, e.g. Django, you can specify the ROOT_FOLDER in settings.py to nginx folder to output static files straight into nginx folder, thus mount once and only for nginx container (mounted again).


Bonus: Runner scripts

Instead of wasting time on typing commands, two shell scripts are present.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published