From 9449f7e149075e1c19cf3fe574388c84a9807c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sat, 25 Jul 2026 17:31:53 +0400 Subject: [PATCH] fix: restructure nginx sample for pre-certbot deployment --- DEPLOY.adoc | 5 ++-- README.adoc | 4 ++-- conf/nginx.conf.sample | 53 ++++++++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/DEPLOY.adoc b/DEPLOY.adoc index c701b18..47e9e5c 100644 --- a/DEPLOY.adoc +++ b/DEPLOY.adoc @@ -117,7 +117,9 @@ chown -R www-data:www-data /var/www/annu-kute-ced/cache === Option A — Nginx + PHP-FPM (recommandée, configuration fournie) -Le fichier `conf/nginx.conf.sample` est l'équivalent Nginx complet du `.htaccess` : mêmes protections (fichiers de configuration, répertoires sensibles, dotfiles, pas de listing), masquage de l'extension `.php`, HTTPS forcé, `no-cache` pour `sw.js` et `site.webmanifest`, plus le cache des assets et gzip. +Le fichier `conf/nginx.conf.sample` est l'équivalent Nginx complet du `.htaccess` : mêmes protections (fichiers de configuration, répertoires sensibles, dotfiles, pas de listing), masquage de l'extension `.php`, `no-cache` pour `sw.js` et `site.webmanifest`, plus le cache des assets et gzip. + +Il est conçu pour un déploiement *en deux temps* : le bloc `:80` sert immédiatement le site en HTTP (prérequis de la validation Certbot, étape 6), et `certbot --nginx` créera ensuite le bloc `443` avec la redirection HTTPS. Aucun certificat n'est donc requis à cette étape — `nginx -t` doit passer tel quel. [source,bash] ---- @@ -125,7 +127,6 @@ Le fichier `conf/nginx.conf.sample` est l'équivalent Nginx complet du `.htacces # - server_name : votre domaine # - root : /var/www/annu-kute-ced # - fastcgi_pass : socket de votre version PHP (ex. /var/run/php/php8.3-fpm.sock) -# - ssl_certificate(_key) : chemins de vos certificats (étape 6) cp conf/nginx.conf.sample /etc/nginx/sites-available/annu-kute-ced ln -s /etc/nginx/sites-available/annu-kute-ced /etc/nginx/sites-enabled/ nginx -t && systemctl reload nginx diff --git a/README.adoc b/README.adoc index 690902d..fb2bc4f 100644 --- a/README.adoc +++ b/README.adoc @@ -785,7 +785,7 @@ NOTE: L'en-tête COEP a été *volontairement retiré* (commit `62d4d99`) : `req ==== Configuration serveur (Nginx, recommandé) -Le fichier `conf/nginx.conf.sample` est l'équivalent Nginx complet du `.htaccess` : mêmes protections (fichiers de configuration et `.sample`, dossiers `/includes/`, `/cache/`, `/docs/`, `/conf/`, fichiers cachés, pas de listing), HTTPS forcé, masquage de l'extension `.php` (URLs propres `/video` au lieu de `/video.php`), `no-cache` pour `sw.js` et `site.webmanifest`, plus le cache des assets et gzip. +Le fichier `conf/nginx.conf.sample` est l'équivalent Nginx complet du `.htaccess` : mêmes protections (fichiers de configuration et `.sample`, dossiers `/includes/`, `/cache/`, `/docs/`, `/conf/`, fichiers cachés, pas de listing), masquage de l'extension `.php` (URLs propres `/video` au lieu de `/video.php`), `no-cache` pour `sw.js` et `site.webmanifest`, plus le cache des assets et gzip. Le bloc `:80` sert le site immédiatement (aucun certificat requis) ; le bloc `443` et la redirection HTTPS sont générés par `certbot --nginx` (voir link:DEPLOY.adoc[DEPLOY.adoc]). [source,bash] ---- @@ -1715,7 +1715,7 @@ NOTE: The COEP header was *deliberately removed* (commit `62d4d99`): `require-co ==== Server configuration (Nginx, recommended) -The `conf/nginx.conf.sample` file is the complete Nginx equivalent of the `.htaccess`: same protections (configuration and `.sample` files, `/includes/`, `/cache/`, `/docs/`, `/conf/` directories, hidden files, no directory listing), HTTPS enforced, `.php` extension masking (clean URLs `/video` instead of `/video.php`), `no-cache` for `sw.js` and `site.webmanifest`, plus asset caching and gzip. +The `conf/nginx.conf.sample` file is the complete Nginx equivalent of the `.htaccess`: same protections (configuration and `.sample` files, `/includes/`, `/cache/`, `/docs/`, `/conf/` directories, hidden files, no directory listing), `.php` extension masking (clean URLs `/video` instead of `/video.php`), `no-cache` for `sw.js` and `site.webmanifest`, plus asset caching and gzip. The `:80` block serves the site immediately (no certificate required); the `443` block and the HTTPS redirect are generated by `certbot --nginx` (see link:DEPLOY.adoc[DEPLOY.adoc]). [source,bash] ---- diff --git a/conf/nginx.conf.sample b/conf/nginx.conf.sample index 0b99125..61a7276 100644 --- a/conf/nginx.conf.sample +++ b/conf/nginx.conf.sample @@ -1,19 +1,20 @@ +# ====================== +# ANNU KUTE CED — Configuration Nginx +# ====================== +# Ce fichier est prévu pour un déploiement en deux temps : +# 1. Avant le certificat SSL : le bloc :80 ci-dessous sert le site en HTTP. +# C'est aussi le prérequis de `certbot --nginx` (validation sur le port 80). +# À ce stade, `nginx -t` doit passer sans aucun certificat. +# 2. Après `certbot --nginx` : Certbot crée le bloc 443 (SSL) et la +# redirection HTTP → HTTPS automatiquement. Un bloc 443 commenté est +# fourni en bas de fichier si vous préférez configurer SSL à la main. + server { listen 80; server_name votre-domaine.com; - return 301 https://$server_name$request_uri; -} - -server { - listen 443 ssl http2; - server_name votre-domaine.com; root /path/to/your/site; index index.php index.html; - # SSL Configuration (adaptez selon votre certificat) - ssl_certificate /path/to/your/certificate.crt; - ssl_certificate_key /path/to/your/private.key; - # ====================== # SÉCURITÉ # ====================== @@ -69,7 +70,7 @@ server { # Traitement des fichiers PHP location ~ \.php$ { include fastcgi_params; - fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Adaptez selon votre version PHP + fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # Adaptez selon votre version PHP fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } @@ -108,4 +109,32 @@ server { add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; -} \ No newline at end of file +} + +# ====================== +# HTTPS (port 443) — après obtention du certificat +# ====================== +# `certbot --nginx` génère automatiquement ce bloc à partir du bloc :80, +# avec la redirection HTTP → HTTPS. Pour une configuration SSL manuelle, +# décommentez et adaptez les chemins des certificats, en reprenant les +# mêmes sections SÉCURITÉ, RÉÉCRITURE D'URL, PHP et OPTIMISATIONS que +# le bloc :80 ci-dessus : +# +# server { +# listen 443 ssl http2; +# server_name votre-domaine.com; +# root /path/to/your/site; +# index index.php index.html; +# +# ssl_certificate /etc/letsencrypt/live/votre-domaine.com/fullchain.pem; +# ssl_certificate_key /etc/letsencrypt/live/votre-domaine.com/privkey.pem; +# +# # ... reprendre ici les mêmes location que dans le bloc :80 ... +# } +# +# # Et remplacez alors le contenu du bloc :80 par une simple redirection : +# # server { +# # listen 80; +# # server_name votre-domaine.com; +# # return 301 https://$server_name$request_uri; +# # }