diff --git a/deploy/nginx/andebol.net.conf b/deploy/nginx/andebol.net.conf new file mode 100644 index 0000000..2f6cdeb --- /dev/null +++ b/deploy/nginx/andebol.net.conf @@ -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"; + } + +} diff --git a/deploy/nginx/conf.d/99-news-platform-wp-map.conf b/deploy/nginx/conf.d/99-news-platform-wp-map.conf new file mode 100644 index 0000000..8594205 --- /dev/null +++ b/deploy/nginx/conf.d/99-news-platform-wp-map.conf @@ -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; +} diff --git a/deploy/nginx/newsproject.bitreport.pt.conf b/deploy/nginx/newsproject.bitreport.pt.conf index 221fd59..1a4d593 100644 --- a/deploy/nginx/newsproject.bitreport.pt.conf +++ b/deploy/nginx/newsproject.bitreport.pt.conf @@ -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/.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; diff --git a/deploy/scripts/deploy.sh b/deploy/scripts/deploy.sh index 38e9897..2d9c7d8 100755 --- a/deploy/scripts/deploy.sh +++ b/deploy/scripts/deploy.sh @@ -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 diff --git a/deploy/scripts/webhook-deploy.sh b/deploy/scripts/webhook-deploy.sh index 1fb7971..a068c1b 100755 --- a/deploy/scripts/webhook-deploy.sh +++ b/deploy/scripts/webhook-deploy.sh @@ -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 diff --git a/docs/deployment.md b/docs/deployment.md index b01a670..72cf7e7 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -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/.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):