← Retour

Déployer un “Hello World” Python avec FastAPI + Gunicorn sur un VPS

Un “hello world FastAPI + Gunicorn + Nginx” ultra-rapide, Linux, sans env vars, sans systemd compliqué, avec un token_admin en dur dans app.py. En 10–15 minutes, l’utilisateur voit sa page web depuis son VPS. Utilisation de ssh.

5.0 EUR · immédiat après paiement · Modes : simple

Python FastAPI Gunicorn VPS Linux SSH

Extrait

Un **“hello world FastAPI + Gunicorn + Nginx” ultra-rapide**, sans env vars, sans systemd compliqué, avec un `token_admin` en dur dans `app.py`.

Objectif clair :

👉 *en 10–15 minutes, tu verra ta page web depuis ton VPS.
---

# 🧪 Tutoriel express

## Déployer un “Hello World” Python avec FastAPI + Gunicorn sur un VPS

*(version speedrun – pour aller vite)*

---

## 1️⃣ Connexion au VPS

```bash
ssh user@IP_DU_VPS
```

Puis :

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-venv python3-pip nginx -y
```

---

## 2️⃣ Création du projet

```bash
mkdir hello_api
cd hello_api
python3 -m venv venv
source venv/bin/activate
pip install fastapi uvicorn gunicorn
```

---

## 3️⃣ Fichier app.py

```bash
nano app.py
```

Contenu :

```python
from fastapi import FastAPI, Header, HTTPException

app = FastAPI()

TOKEN_ADMIN = "mon_token_secret"

@app.get("/")
def root():
    return {"message": "Hello Artisan Numérique"}

@app.get("/admin")
def admin(x_token: str = Header(None)):
    if x_token != TOKEN_ADMIN:
        raise HTTPException(status_code=401, detail="Unauthorized")
    return {"status": "admin ok"}
```

➡️ Oui : token en dur.
➡️ C’est volontaire pour ce

[...]

L’extrait est tronqué. Après achat, tu reçois le texte complet + licence signée.