fix(nginx): default_server for all NPM hostnames + WP port map

Use default_server and server_name _ so domains like andebol.net reach Astro
instead of the Debian nginx welcome page. Install map Host→WordPress port
(8080 default, andebol.net→8081). deploy.sh and webhook-deploy install
conf.d snippet and remove sites-enabled/default.

docs/deployment.md: document multi-domain NPM workflow.

Refs: BIT-345
This commit is contained in:
Artur Moreira committed 2026-03-25 12:34:18 +00:00
1 parent 49aef86119
commit e15e88ef6c
6 files changed
+183 -14

No files matched your search

+140
View File
@@ -0,0 +1,140 @@
# Deprecated — do not symlink into sites-enabled alongside the main vhost.
# Use deploy/nginx/newsproject.bitreport.pt.conf (default_server) + conf.d/99-news-platform-wp-map.conf
# so andebol.net is served without a separate CT Nginx file (NPM only).
server {
listen 80;
listen [::]:80;
server_name andebol.net;
set $forwarded_proto $scheme;
if ($http_x_forwarded_proto) {
set $forwarded_proto $http_x_forwarded_proto;
}
access_log /var/log/nginx/andebol.access.log;
error_log /var/log/nginx/andebol.error.log warn;
# Astro SSR frontend — Host header routes to andebol.net domain config
location / {
proxy_pass http://127.0.0.1:4321;
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 $forwarded_proto;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
# WordPress (Docker :8081) — restricted to internal/admin access
location ^~ /wp-admin/ {
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8081;
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 $forwarded_proto;
proxy_read_timeout 120s;
proxy_send_timeout 120s;
}
location = /wp-login.php {
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8081;
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 $forwarded_proto;
proxy_read_timeout 120s;
}
location ^~ /wp-content/ {
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8081;
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 $forwarded_proto;
proxy_read_timeout 120s;
}
location ^~ /wp-includes/ {
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8081;
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 $forwarded_proto;
proxy_read_timeout 120s;
}
location ^~ /wp-json/ {
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8081;
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 $forwarded_proto;
proxy_read_timeout 120s;
}
location = /health {
proxy_pass http://127.0.0.1:3200/health;
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 $forwarded_proto;
proxy_read_timeout 10s;
}
location /api/ {
proxy_pass http://127.0.0.1:3200/;
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 $forwarded_proto;
proxy_read_timeout 10s;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|ttf|eot)$ {
proxy_pass http://127.0.0.1:4321;
proxy_set_header Host $host;
expires 7d;
add_header Cache-Control "public, immutable";
}
}
@@ -0,0 +1,7 @@
# Installed to /etc/nginx/conf.d/ (http context). Used by the news-platform site vhost
# so a single default_server can proxy WordPress to the correct Docker port per domain.
map $host $news_wp_port {
default 8080;
andebol.net 8081;
www.andebol.net 8081;
}
+15 -12
View File
@@ -1,7 +1,11 @@
# Catch-all vhost for the news-platform CT. NPM (or any edge proxy) forwards HTTP here;
# `Host` is preserved so Astro + bridge load `config/domains/<host>.json`.
# New public domains: add DNS + NPM proxy to this CT — no extra Nginx `server_name` here.
# WordPress port per domain: `deploy/nginx/conf.d/99-news-platform-wp-map.conf`.
server {
listen 80;
listen [::]:80;
server_name newsproject.bitreport.pt;
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
# NPM (or another edge proxy) terminates TLS and forwards HTTP here. Preserve the
# client-facing scheme instead of always sending $scheme (which would be "http").
@@ -10,9 +14,8 @@ server {
set $forwarded_proto $http_x_forwarded_proto;
}
# Access and error logs
access_log /var/log/nginx/newsproject.access.log;
error_log /var/log/nginx/newsproject.error.log warn;
access_log /var/log/nginx/news-platform.access.log;
error_log /var/log/nginx/news-platform.error.log warn;
# WordPress locations below use allow/deny on $remote_addr. If the previous hop is
# Nginx Proxy Manager (or any peer on 10/172.16/192.168), $remote_addr is that proxy,
@@ -39,7 +42,7 @@ server {
proxy_send_timeout 30s;
}
# WordPress (Docker :8080) — admin + editor + REST for logged-in users.
# WordPress (Docker — port from $news_wp_port, usually 8080; andebol.net → 8081) — admin + REST.
# allow/deny use $remote_addr on the CT (often the proxy hop, not the browser — see header comment).
# Do not widen `allow` or remove `deny all` without board risk acceptance.
location ^~ /wp-admin/ {
@@ -49,7 +52,7 @@ server {
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8080;
proxy_pass http://127.0.0.1:$news_wp_port;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -66,7 +69,7 @@ server {
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8080;
proxy_pass http://127.0.0.1:$news_wp_port;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -82,7 +85,7 @@ server {
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8080;
proxy_pass http://127.0.0.1:$news_wp_port;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -98,7 +101,7 @@ server {
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8080;
proxy_pass http://127.0.0.1:$news_wp_port;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -115,7 +118,7 @@ server {
allow 192.168.0.0/16;
deny all;
proxy_pass http://127.0.0.1:8080;
proxy_pass http://127.0.0.1:$news_wp_port;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
+9
View File
@@ -79,10 +79,19 @@ systemctl daemon-reload
# --- Nginx ---
log "Installing Nginx config..."
mkdir -p /etc/nginx/conf.d
MAP_SRC="$APP_DIR/deploy/nginx/conf.d/99-news-platform-wp-map.conf"
MAP_DST="/etc/nginx/conf.d/99-news-platform-wp-map.conf"
if [ -f "$MAP_SRC" ]; then
cp "$MAP_SRC" "$MAP_DST"
log " Installed $MAP_DST (Host → WordPress port)"
fi
NGINX_CONF="/etc/nginx/sites-available/newsproject.bitreport.pt.conf"
NGINX_LINK="/etc/nginx/sites-enabled/newsproject.bitreport.pt.conf"
cp "$APP_DIR/deploy/nginx/newsproject.bitreport.pt.conf" "$NGINX_CONF"
ln -sf "$NGINX_CONF" "$NGINX_LINK"
# Debian/Ubuntu default site catches requests when no server_name matches — remove so our default_server vhost wins
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx
+6
View File
@@ -67,8 +67,14 @@ fi
# Reload nginx if config changed
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^deploy/nginx/"; then
log "Nginx config changed — reloading..."
mkdir -p /etc/nginx/conf.d
if [ -f "$APP_DIR/deploy/nginx/conf.d/99-news-platform-wp-map.conf" ]; then
cp "$APP_DIR/deploy/nginx/conf.d/99-news-platform-wp-map.conf" \
/etc/nginx/conf.d/99-news-platform-wp-map.conf
fi
cp "$APP_DIR/deploy/nginx/newsproject.bitreport.pt.conf" \
/etc/nginx/sites-available/newsproject.bitreport.pt.conf
rm -f /etc/nginx/sites-enabled/default
nginx -t && systemctl reload nginx
log "Nginx reloaded."
fi
+6 -2
View File
@@ -61,9 +61,13 @@ It installs nginx, Redis, Docker (+ compose plugin), Node.js 22, and PM2, and en
---
## Nginx Config (`deploy/nginx/newsproject.bitreport.pt.conf`)
## Nginx Config (`deploy/nginx/newsproject.bitreport.pt.conf` + `conf.d/`)
The canonical site config is **`deploy/nginx/newsproject.bitreport.pt.conf`** (install via `deploy/scripts/deploy.sh`). It proxies `/` to Astro (`:4321`), `/api/` to the Fastify bridge (`:3200`), **`/health`** to the bridge health JSON, and WordPress paths to Docker (`:8080`).
The canonical site config is **`deploy/nginx/newsproject.bitreport.pt.conf`** (install via `deploy/scripts/deploy.sh`). It listens as **`default_server`** on port 80 with **`server_name _`**, so **any hostname** NPM forwards to this CT hits the news stack (no per-domain `server_name` on the CT). Add **`config/domains/<hostname>.json`** + a **proxy host in NPM**; redeploy/restart bridge if needed.
**`deploy/nginx/conf.d/99-news-platform-wp-map.conf`** maps `Host` → WordPress upstream port (`8080` default; `andebol.net` → `8081`). If you add another domain with its own Docker WordPress port, extend that `map` and reload Nginx.
`deploy/scripts/deploy.sh` removes **`/etc/nginx/sites-enabled/default`** so the default Debian welcome page does not steal unmatched hosts.
Minimal shape (reference only — use the checked-in file, not this excerpt):