From ce91ca2f21b880740153fc9d1a1c958b591612a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Mar 2026 20:04:55 +0000 Subject: [PATCH] Fix nginx config: use 127.0.0.1 not host.docker.internal, standard /slug/ pattern --- backend/src/nginx.js | 26 ++++++-------------------- frontend/package.json | 2 +- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/backend/src/nginx.js b/backend/src/nginx.js index 9f26227..fd2619c 100644 --- a/backend/src/nginx.js +++ b/backend/src/nginx.js @@ -6,16 +6,13 @@ const NGINX_CONF_DIR = path.join(__dirname, '..', 'nginx', 'conf.d'); const SHOPS_LOCATIONS_FILE = path.join(NGINX_CONF_DIR, 'shops-locations.inc'); // Generate a path-based location block for a shop and append it to the -// shared shops-locations.inc file. This replaces the old per-shop -// subdomain server block approach so that shops are reachable at -// domain.com/ instead of .domain.com. +// shared shops-locations.inc file. Shops are reachable at domain.com// +// Next.js is configured with basePath=/ so the full path is passed through. function generateShopConfig(slug, port) { const block = ` # Shop: ${slug} -location /${slug} { - rewrite ^/${slug}/(.*) /$1 break; - rewrite ^/${slug}$ / break; - proxy_pass http://host.docker.internal:${port}; +location /${slug}/ { + proxy_pass http://127.0.0.1:${port}; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -23,18 +20,8 @@ location /${slug} { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-Prefix /${slug}; proxy_cache_bypass $http_upgrade; } - -location /${slug}/api/images/ { - proxy_pass http://host.docker.internal:${port}; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; -} `; if (!fs.existsSync(NGINX_CONF_DIR)) { @@ -50,10 +37,9 @@ function removeShopConfig(slug) { if (!fs.existsSync(SHOPS_LOCATIONS_FILE)) return; const content = fs.readFileSync(SHOPS_LOCATIONS_FILE, 'utf8'); - // Each shop has two location blocks: main + /api/images/, both under a "# Shop:" comment const escaped = slug.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const pattern = new RegExp( - `\\n# Shop: ${escaped}\\nlocation /${escaped}[\\s\\S]*?\\n}\\n\\nlocation /${escaped}/api/images/[\\s\\S]*?\\n}\\n`, + `\\n# Shop: ${escaped}\\nlocation /${escaped}/[\\s\\S]*?\\n}\\n`, 'g' ); const updated = content.replace(pattern, ''); @@ -62,7 +48,7 @@ function removeShopConfig(slug) { function reloadNginx() { try { - execSync('docker exec nginx-proxy nginx -s reload', { stdio: 'pipe' }); + execSync('nginx -t && systemctl reload nginx', { stdio: 'pipe' }); return true; } catch (err) { console.error('Failed to reload nginx:', err.message); diff --git a/frontend/package.json b/frontend/package.json index 46f2bd1..fdfd8f3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "shuttle-platform-frontend", "private": true, - "version": "2.5.0", + "version": "2.5.1", "type": "module", "scripts": { "dev": "vite",