|
| 1 | +# Nginx + Certbot (Let's Encrypt) |
| 2 | + |
| 3 | +Reverse proxy Nginx avec gestion automatique des certificats SSL via Certbot/Let's Encrypt. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### 1. Configuration |
| 8 | + |
| 9 | +Éditer les fichiers de configuration : |
| 10 | + |
| 11 | +```bash |
| 12 | +# Modifier le domaine dans nginx/conf.d/default.conf |
| 13 | +# Remplacer "example.com" par votre domaine |
| 14 | + |
| 15 | +# Modifier init-letsencrypt.sh |
| 16 | +# - domains=(votre-domaine.com www.votre-domaine.com) |
| 17 | +# - email="votre-email@example.com" |
| 18 | +``` |
| 19 | + |
| 20 | +### 2. Première initialisation |
| 21 | + |
| 22 | +```bash |
| 23 | +# Générer le premier certificat |
| 24 | +./init-letsencrypt.sh |
| 25 | +``` |
| 26 | + |
| 27 | +### 3. Démarrage |
| 28 | + |
| 29 | +```bash |
| 30 | +docker compose up -d |
| 31 | +``` |
| 32 | + |
| 33 | +## Fonctionnement |
| 34 | + |
| 35 | +- **Nginx** : Reverse proxy avec SSL termination |
| 36 | +- **Certbot** : Renouvellement automatique des certificats (toutes les 12h) |
| 37 | +- **Auto-reload** : Nginx recharge la config toutes les 6h |
| 38 | + |
| 39 | +## Structure |
| 40 | + |
| 41 | +``` |
| 42 | +nginx-certbot/ |
| 43 | +├── compose.yml |
| 44 | +├── init-letsencrypt.sh # Script d'initialisation |
| 45 | +├── nginx/ |
| 46 | +│ └── conf.d/ |
| 47 | +│ └── default.conf # Configuration Nginx |
| 48 | +└── certbot/ |
| 49 | + ├── conf/ # Certificats Let's Encrypt |
| 50 | + └── www/ # Challenge ACME |
| 51 | +``` |
| 52 | + |
| 53 | +## Ajouter un nouveau site |
| 54 | + |
| 55 | +1. Créer un fichier dans `nginx/conf.d/` (ex: `mysite.conf`) |
| 56 | +2. Ajouter le domaine dans `init-letsencrypt.sh` |
| 57 | +3. Relancer le script d'initialisation |
| 58 | + |
| 59 | +### Exemple de configuration proxy |
| 60 | + |
| 61 | +```nginx |
| 62 | +server { |
| 63 | + listen 80; |
| 64 | + server_name myapp.example.com; |
| 65 | +
|
| 66 | + location /.well-known/acme-challenge/ { |
| 67 | + root /var/www/certbot; |
| 68 | + } |
| 69 | +
|
| 70 | + location / { |
| 71 | + return 301 https://$host$request_uri; |
| 72 | + } |
| 73 | +} |
| 74 | +
|
| 75 | +server { |
| 76 | + listen 443 ssl; |
| 77 | + server_name myapp.example.com; |
| 78 | +
|
| 79 | + ssl_certificate /etc/letsencrypt/live/myapp.example.com/fullchain.pem; |
| 80 | + ssl_certificate_key /etc/letsencrypt/live/myapp.example.com/privkey.pem; |
| 81 | +
|
| 82 | + location / { |
| 83 | + proxy_pass http://myapp:8080; |
| 84 | + proxy_set_header Host $host; |
| 85 | + proxy_set_header X-Real-IP $remote_addr; |
| 86 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 87 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +## Mode staging |
| 93 | + |
| 94 | +Pour les tests, utilisez le serveur staging de Let's Encrypt pour éviter les rate limits : |
| 95 | + |
| 96 | +```bash |
| 97 | +# Dans init-letsencrypt.sh |
| 98 | +staging=1 |
| 99 | +``` |
| 100 | + |
| 101 | +## Liens |
| 102 | + |
| 103 | +- [Certbot Documentation](https://certbot.eff.org/docs/) |
| 104 | +- [Let's Encrypt](https://letsencrypt.org/) |
| 105 | +- [Nginx Documentation](https://nginx.org/en/docs/) |
0 commit comments