Align README and deployment.md with reality: allow/deny use $remote_addr on the CT, so a private-IP reverse proxy makes /wp-admin/ reachable from the public Internet. Add nginx header comments and optional real_ip notes. Co-Authored-By: Paperclip <[email protected]> Made-with: Cursor
7.5 KiB
Deployment — LXC on Proxmox
Status: Stub — implementation in progress (BIT-345)
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), MySQL (Docker), and Redis.
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
└── mysql :3306 (internal only)
Setup Script (deploy/lxc/setup.sh)
#!/bin/bash
set -euo pipefail
# System
apt-get update && apt-get upgrade -y
apt-get install -y curl git nginx redis-server docker.io docker-compose-plugin
# Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs
# PM2
npm install -g pm2
# Redis (start + enable)
systemctl enable --now redis-server
# Docker
systemctl enable --now docker
echo "Base setup complete. Deploy services manually or run per-service scripts."
Nginx Config (deploy/nginx/newsproject.conf)
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 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 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.
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 |
| 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.
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 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 (user step)
- Smoke test:
curl https://newsproject.bitreport.pt/returns HTML - 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.