Add wordpress-ensure-public-url.sh (exit 2 when .env updated) and wordpress-sync-options-url.sh to align siteurl/home with HTTPS. Wire into deploy.sh and webhook-deploy.sh for /opt/news-platform only so the board does not need manual .env or SQL for BIT-470/BIT-471. Made-with: Cursor
9.5 KiB
Deployment — LXC on Proxmox
NPM (manual, board): Configure Nginx Proxy Manager with hostname
newsproject.bitreport.ptpointing tohttp://<CT-ip>:80, TLS enabled. Termination stays at NPM; the CT Nginx listens on port 80 only.
Overview
The platform runs on a single LXC container on Proxmox for the initial test deployment. The container hosts all services: Nginx reverse proxy, Astro frontend (Node.js), Fastify bridge (Node.js), WordPress (Docker), MariaDB (Docker), and Redis.
Bootstrap order: create the CT → run deploy/lxc/setup.sh on the CT → clone or sync repo to /opt/news-platform → run deploy/scripts/deploy.sh → configure NPM as above → run deploy/scripts/smoke-newsproject.sh with BASE_URL=https://newsproject.bitreport.pt.
LXC Container Spec
| Property | Value |
|---|---|
| Name | news-project-test |
| OS | Ubuntu 24.04 LTS |
| CPU | 2 cores |
| RAM | 4 GB |
| Disk | 20 GB |
| Network | Bridge (vmbr0), DHCP or static IP |
| Domain | newsproject.bitreport.pt |
Service Layout
LXC: news-project-test
│
├── nginx (host) :80, :443
│ └── reverse proxy → :4321 (Astro)
│
├── astro-frontend (PM2 / systemd) :4321
│ └── node dist/server/entry.mjs
│
├── fastify-bridge (PM2 / systemd) :3200
│ └── node dist/server.js
│
├── redis (host or Docker) :6379
│
└── Docker Compose
├── wordpress :8080
└── mariadb (db) :3306 (internal only)
Setup Script (deploy/lxc/setup.sh)
Versioned script on the repo (run as root on a fresh Ubuntu 24.04 CT):
sudo bash /opt/news-platform/deploy/lxc/setup.sh
It installs nginx, Redis, Docker (+ compose plugin), Node.js 22, and PM2, and enables docker and redis-server.
Nginx Config (deploy/nginx/newsproject.bitreport.pt.conf)
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).
Minimal shape (reference only — use the checked-in file, not this excerpt):
server {
listen 80;
server_name newsproject.bitreport.pt;
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 $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
HTTPS/TLS is terminated at Nginx Proxy Manager (NPM), which the board 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 source addresses as seen by this Nginx ($remote_addr). O bloco server define X-Forwarded-Proto a partir de $http_x_forwarded_proto (NPM) com fallback para $scheme, para o WordPress não assumir HTTP plano quando o browser usa HTTPS.
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.
WordPress (Docker Compose)
A stack real está versionada em wordpress/docker-compose.yml (não duplicar aqui — evita deriva face à produção).
| Item | Valor actual |
|---|---|
| Database | MariaDB 11 (mariadb:11), serviço db, porta 3306 só na rede Compose |
| WordPress | wordpress:6-php8.3-apache, WORDPRESS_DB_HOST: db:3306 |
| URL pública | Preferir WORDPRESS_PUBLIC_URL=https://newsproject.bitreport.pt no wordpress/.env. Se faltar, o wp-config infere https:// + Host quando o pedido chega via Nginx do CT (cabeçalhos X-Forwarded-For + X-Forwarded-Proto; este último deve reflectir o HTTPS do NPM — ver deploy/nginx/newsproject.bitreport.pt.conf). |
| Arranque | depends_on: db com condition: service_healthy |
| Volumes | db_data (MySQL), wp_content (uploads/plugins) |
| Healthchecks | db: script oficial --innodb_initialized; wordpress: curl ao REST /wp-json/wp/v2/ |
Operação e recuperação de «Error establishing a database connection»: wordpress/README.md (secção homónima). No CT, após cd /opt/news-platform/wordpress: bash scripts/verify-db-connection.sh confirma em cadeia ps + healthcheck do MariaDB + ligação desde o contentor wordpress.
Automação LXC (APP_DIR=/opt/news-platform apenas): deploy/scripts/wordpress-ensure-public-url.sh corrige WORDPRESS_PUBLIC_URL no wordpress/.env para https://newsproject.bitreport.pt quando ainda está vazio ou em http://localhost:8080. deploy/scripts/wordpress-sync-options-url.sh actualiza siteurl/home na tabela wp_*options para o mesmo URL (resolve redirects para localhost mesmo após instalação antiga). São invocados por deploy/scripts/deploy.sh e deploy/scripts/webhook-deploy.sh; o primeiro devolve código de saída 2 quando alterou o .env para o caller fazer docker compose up -d --force-recreate wordpress.
Service Start (PM2)
# Frontend
cd /opt/news-platform/frontend
pm2 start dist/server/entry.mjs --name astro-frontend -- --port 4321
# Bridge
cd /opt/news-platform/bridge
pm2 start dist/server.js --name fastify-bridge -- --port 3200
pm2 save
pm2 startup
Deployment Checklist
- LXC container created and running
- Base packages installed (Node 22, nginx, redis, docker)
- Git repo cloned to
/opt/news-platform/ config/domains/newsproject.bitreport.pt.jsonpopulated- Bridge dependencies installed and built
- Frontend dependencies installed and built
- WordPress Docker stack running (
docker compose up -d) WORDPRESS_PUBLIC_URL=https://newsproject.bitreport.ptemwordpress/.env(alinhado com NPM / browser)- WordPress configured (admin user, permalink structure
/%category%/%postname%/) - Bridge invalidator plugin activated in WP
- PM2 processes started and saved
- Nginx config symlinked and nginx reloaded
- DNS points
newsproject.bitreport.ptto container IP - NPM configured for HTTPS (board): hostname
newsproject.bitreport.pt→ CT port 80 - Smoke:
BASE_URL=https://newsproject.bitreport.pt bash deploy/scripts/smoke-newsproject.sh(orBASE_URL=http://127.0.0.1on the CT) - Sitemap accessible at
/sitemap.xml
Automatic deploy (Gitea → LXC)
After the first manual bootstrap, pushes to main can trigger a pull + selective rebuild on the container.
-
Script —
deploy/scripts/webhook-deploy.shcomparesHEADtoorigin/main, runsgit reset --hard, rebuilds bridge/frontend when those trees change, reloads nginx whendeploy/nginx/changes, restarts bridge + frontend whenconfig/changes (domain JSON is cached in the bridge process), and runsdocker composewhenwordpress/changes. -
Hook server —
deploy/scripts/deploy-hook-server.mjslistens on loopback (default127.0.0.1:9090), pathPOST /hook, and acceptsAuthorization: Bearer <token>orX-Deploy-TokenmatchingDEPLOY_HOOK_TOKEN. It returns202and runs the script in the background. Systemd unit:deploy/systemd/news-deploy-hook.service; env template:deploy/systemd/deploy-hook.env.example→/etc/news-platform/deploy-hook.env. -
Gitea — In the repo, add a Webhook on push to
main, URLhttp://<CT-ip-or-dns>:9090/hook(only if Gitea can reach that host/port; otherwise use a self-hosted runner or SSH task that curls the hook from inside the VPN). Set a custom header or Bearer token to the same value asDEPLOY_HOOK_TOKEN. Do not expose the hook to the public internet without token and firewall allowlisting. -
Alternative — Gitea Actions can
curl -fsS -X POST -H "Authorization: Bearer $TOKEN" http://.../hookfrom a runner that has network access to the CT.
Future: Multi-Container
When the platform scales beyond a single test container, each service moves to its own LXC or VM:
| Service | Container |
|---|---|
| Astro frontend | news-frontend-01, news-frontend-02 |
| Fastify bridge | news-bridge-01 |
| WordPress | news-wp-01 |
| MySQL | news-db-01 |
| Redis | news-redis-01 |
| Nginx LB | news-lb-01 |
Cloudflare sits in front of the load balancer.