FastAPI Deployment Guide: A Comprehensive Process from Local Development to Cloud Server Deployment

This article introduces the complete deployment process of FastAPI, from local development to cloud server deployment. First, install FastAPI and Uvicorn locally, write a simple interface (e.g., `main.py`), and test it with `uvicorn`. Next, purchase a Linux cloud server (e.g., Ubuntu), obtain information such as the IP and username, and connect remotely via SSH. The server needs to install Python 3 and dependencies, create a project directory, upload the code, generate `requirements.txt` and install dependencies. For production environment configuration, set up a systemd service, enable auto-start at boot (`fastapi.service`), and open the firewall port 8000. Nginx reverse proxy is recommended, with HTTPS configured through Certbot. After deployment, maintain the service via logs, and re-upload and restart the code when updated. For complex projects, Docker containerization deployment can be adopted. The core process: local debugging → server preparation → environment setup → service startup → security configuration → maintenance, ensuring the API stably serves external requests.

Read More
Getting Started with Flask Deployment: Gunicorn and Nginx Configuration Tutorial

This article introduces a solution for deploying Flask applications in a production environment: since Flask's built-in development server does not support high concurrency and is insecure, it needs to be paired with Gunicorn (a WSGI server) and Nginx (a reverse proxy). The steps are as follows: First, install Gunicorn (`pip install gunicorn`) and Nginx (for Ubuntu/Debian, use `apt install nginx`). When starting Gunicorn, use `gunicorn -w 4 -b 127.0.0.1:8000 app:app` (where `-w` sets the number of workers, `-b` binds the address and port, and `app:app` specifies the application entry). Next, configure Nginx by creating a configuration file (e.g., `flask_app`), set up reverse proxy to Gunicorn (`proxy_pass`), and handle static resources (`location /static`). Enable the configuration and restart Nginx. For verification, access `http://localhost` or test with `curl`. For advanced use, configure Gunicorn to start automatically on boot via systemd. Common issues include port occupation and incorrect static file paths, which require checking Gunicorn status or firewall rules. The core is running the application through Gunicorn and using Nginx.

Read More