On place Nginx devant Gunicorn. Internet -> Nginx -> Gunicorn -> Flask
Pourquoi ?
- Sécurité : Nginx est un bouclier robuste contre les attaques.
- HTTPS : Nginx gère le cryptage SSL (avec Let's Encrypt).
- Fichiers Statiques : Nginx sert les images/CSS 100x plus vite que Python.
Configuration Nginx (/etc/nginx/sites-available/mon_projet)
server {
listen 80;
server_name mon-site.com;
location / {
# On passe la main à Gunicorn
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /static {
# Nginx sert les fichiers directement (sans réveiller Python)
alias /home/utilisateur/mon_projet/app/static;
}
}
C'est la config standard. En production, on ajouterait HTTPS (port 443).