diff --git a/deploy/nginx/newsproject.bitreport.pt.conf b/deploy/nginx/newsproject.bitreport.pt.conf index 2cf405e..c025b5b 100644 --- a/deploy/nginx/newsproject.bitreport.pt.conf +++ b/deploy/nginx/newsproject.bitreport.pt.conf @@ -7,6 +7,17 @@ server { access_log /var/log/nginx/newsproject.access.log; error_log /var/log/nginx/newsproject.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, + # not the browser — so allow 10.0.0.0/8 lets every public client that reaches this host + # through NPM hit /wp-admin/ (effective worldwide). To enforce on real clients, enable + # real_ip and set_real_ip_from ONLY trusted proxy IPs, then tune allow — see docs/deployment.md. + # + # Example (uncomment and set the NPM/container IP when ready to test): + # real_ip_header X-Forwarded-For; + # real_ip_recursive on; + # set_real_ip_from 10.0.0.0/8; + # Astro SSR frontend — main entry point location / { proxy_pass http://127.0.0.1:4321; @@ -22,8 +33,8 @@ server { } # WordPress (Docker :8080) — admin + editor + REST for logged-in users. - # Restricted to loopback + RFC1918 (VPN/LAN). Tighten `allow` with DevOps if needed. - # Do not remove `deny all` for public Internet without board risk acceptance. + # 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/ { allow 127.0.0.1; allow 10.0.0.0/8; diff --git a/docs/deployment.md b/docs/deployment.md index 3993f42..0b346e2 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -97,7 +97,9 @@ server { HTTPS/TLS is terminated at Nginx Proxy Manager (NPM), which the user configures manually. -The checked-in `deploy/nginx/newsproject.bitreport.pt.conf` proxies **`/wp-admin/`**, **`wp-login.php`**, **`/wp-content/`**, **`/wp-includes/`**, and **`/wp-json/`** to WordPress on `127.0.0.1:8080` with **`allow`** for loopback and RFC1918 addresses only (not the public Internet). Tighten or extend `allow` with DevOps if your hop (NPM, VPN) uses different source IPs. +The checked-in `deploy/nginx/newsproject.bitreport.pt.conf` proxies **`/wp-admin/`**, **`wp-login.php`**, **`/wp-content/`**, **`/wp-includes/`**, and **`/wp-json/`** to WordPress on `127.0.0.1:8080` with **`allow`** for loopback and RFC1918 source addresses **as seen by this Nginx** (`$remote_addr`). + +**`wp-admin` and “public” reachability:** with **Nginx Proxy Manager** (or any reverse proxy on a private IP) in front of this CT, browsers worldwide connect to the public hostname, but the TCP client at the CT is the **proxy**. That address is usually inside `10.0.0.0/8` (or similar), so it matches `allow` — meaning **`https://…/wp-admin/` is reachable from the public Internet** through that chain, even though the config reads “RFC1918 only”. This matches operational reality; it is not a substitute for VPN-only admin unless you add controls at NPM/Cloudflare or enable **`ngx_http_realip_module`**: `set_real_ip_from` limited to **trusted** proxy IPs, `real_ip_header X-Forwarded-For`, then `allow`/`deny` apply to the restored client IP (test carefully; misconfiguration allows IP spoofing). **WordPress 500 + «database connection»:** se o HTML do erro citar `db:3306`, tratar como stack Docker no CT (serviço `db`, `.env`, volumes) — ver `wordpress/README.md` § *Error establishing a database connection*. diff --git a/wordpress/README.md b/wordpress/README.md index feb659c..82707eb 100644 --- a/wordpress/README.md +++ b/wordpress/README.md @@ -54,7 +54,7 @@ The setup script creates: ## Acesso ao `wp-admin` (operacional) -O domínio público **não** expõe o WordPress (apenas Astro + bridge em Nginx). Isto é intencional. +No mesmo `server_name` público, **`/`** é Astro + bridge; **`/wp-admin/`**, **`/wp-json/`**, **`/wp-content/`**, etc. são proxied para o WordPress em Docker (`deploy/nginx/newsproject.bitreport.pt.conf`). Ou seja, o hostname público **inclui** caminhos WordPress — não só o site estático. | Onde estás | URL | |------------|-----| @@ -71,13 +71,17 @@ Depois no browser: `http://localhost:8080/wp-admin/` Credenciais: cofre da equipa (nunca em git). Se ainda não existir utilizador admin, segue a secção *Quick Start* (`setup.sh`). -**Via domínio (Nginx no CT):** após `nginx -t && systemctl reload nginx` com o ficheiro em `deploy/nginx/newsproject.bitreport.pt.conf`, podes usar **`https://newsproject.bitreport.pt/wp-admin/`** a partir de redes privadas (RFC1918 + loopback) — o proxy encaminha para Docker `:8080`. O editor de blocos precisa de `/wp-json/`; já está incluído com a mesma política de `allow`. +**Via domínio (`https://newsproject.bitreport.pt/wp-admin/`):** o Nginx no CT aplica `allow`/`deny` com base em **`$remote_addr`** (o cliente TCP **visto pelo Nginx do CT**). + +**Alcance “todo o mundo” com Nginx Proxy Manager (ou outro hop em RFC1918):** o tráfego público chega ao CT com `$remote_addr` = **IP interno do proxy** (ex.: rede `10.0.0.0/8`). Como esse IP está nos `allow`, o pedido é aceite — **qualquer utilizador que consiga abrir o domínio público** (em qualquer parte do mundo) segue o mesmo caminho. Isto **não** é equivalente a “só redes privadas no browser”; é “só quem o Nginx do CT vê como RFC1918”, o que inclui o hop NPM. + +Para **restringir** o `/wp-admin/` a utilizadores reais em redes privadas (ou a IPs conhecidos), é preciso outra camada ou `real_ip` bem configurado: `set_real_ip_from` **apenas** para IPs dos proxies de confiança, `real_ip_header X-Forwarded-For`, e depois ajustar `allow` ao resultado — ou controlar acesso no **NPM** / Cloudflare / VPN. Ver `docs/deployment.md` (secção homónima). **Directo ao LXC:** `http://10.10.50.140:8080/wp-admin/` — o `docker compose` publica `8080` em todas as interfaces por omissão; se não abre, verifica **firewall do CT**, **Proxmox**, e rota VPN até `10.10.50.0/24`. **Redirects do WordPress:** se o login redirecionar para um host errado, alinha `WP_HOME` / `WP_SITEURL` (env Docker ou `wp option`) com o URL que usas no browser (domínio público ou IP:8080). -**Atenção:** atrás de **Nginx Proxy Manager**, o Nginx do CT vê como cliente o **IP do NPM** — a subnet desse host tem de cair dentro dos `allow` (ex.: `10.0.0.0/8`). Cloudflare ou outro proxy extra exige `set_real_ip_from` / `real_ip_header` ou lista de IPs ajustada. +**Cloudflare / cadeia extra:** além do NPM, cada hop pode exigir `set_real_ip_from` / `real_ip_header` e lista de IPs ajustada; caso contrário, `allow` continua a reflectir só o último salto visto pelo CT. ### «Error establishing a database connection» (HTTP 500 no `/wp-admin/`)