From 63240f2e52c4be7392d9990a42071ea61f84086e Mon Sep 17 00:00:00 2001 From: Sam DEPARDIEU Date: Tue, 7 Jul 2026 19:33:47 +0200 Subject: [PATCH] =?UTF-8?q?Corrige=20la=20redirection=20vers=20localhost?= =?UTF-8?q?=20derri=C3=A8re=20le=20reverse=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - nginx.conf: sert l'application sur 80 et 443 sans redirection interne (l'ancien "return 301 https://\$server_name" renvoyait vers localhost, server_name étant codé à localhost). NPM gère déjà le TLS/redirect public. - bootstrap/app.php: trustProxies(at: '*') pour que Laravel lise X-Forwarded-Proto/Host et génère les bonnes URL derrière NPM. Co-Authored-By: Claude Opus 4.8 --- bootstrap/app.php | 5 +++++ nginx.conf | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index f2ba62f..b6e8ea4 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -13,6 +13,11 @@ return Application::configure(basePath: dirname(__DIR__)) health: '/up', ) ->withMiddleware(function (Middleware $middleware): void { + // L'application tourne derrière nginx-proxy-manager : on fait confiance + // au reverse proxy pour lire X-Forwarded-Proto/Host (sinon Laravel croit + // être en HTTP et génère de mauvaises URL / redirections). + $middleware->trustProxies(at: '*'); + $middleware->append(ForceHttps::class); $middleware->append(SecurityHeaders::class); }) diff --git a/nginx.conf b/nginx.conf index 5dc3d00..c7eb910 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,14 +1,15 @@ +# Ce serveur nginx est DERRIÈRE nginx-proxy-manager (NPM), qui termine le TLS +# public (certificat Let's Encrypt) et force déjà HTTP -> HTTPS pour le domaine. +# Ici, on se contente donc de SERVIR l'application, sans redirection interne +# (l'ancienne redirection vers https://$server_name renvoyait vers "localhost"). server { listen 80; - server_name localhost; - return 301 https://$server_name$request_uri; -} - -server { listen 443 ssl; - server_name localhost; + server_name app.sam-coffre.duckdns.org localhost _; + ssl_certificate /var/www/cert.pem; ssl_certificate_key /var/www/cert.key; + index index.php index.html; root /var/www/public; @@ -26,4 +27,4 @@ server { try_files $uri $uri/ /index.php?$query_string; gzip_static on; } -} \ No newline at end of file +}