HomeToolsAbout

FastAPI Config with Nginx

Python Config

Install Python in Server

sudo apt install -y python3-pip nginx

Nginx Configuration

Nginx is used to route traffic to the Fastapi server

Edit default config

Editing default configurations that comes with nginx installation

sudo vim /etc/nginx/nginx.conf sudo vim /etc/nginx/sites-enabled/new_file_name

Setup nginx in the new file

server { listen 80; server_name 0.0.0.0; location / { proxy_pass http://127.0.0.1:8000; } }

Run

# Start nginx sudo service nginx restart # Test nginx sudo nginx -t # View Nginx Error Log sudo nano /var/log/nginx/error.log

Uvicorn

Install uvicorn

Uvicorn is the server runner

pip install uvicorn

Run fastapi using Uvicorn

uvicorn file_name:app

Console Output

Make output console scrollable

"your_command" | less
AboutContact