cd ../articles

System Networking NexiCloud

NexiCloud, part 1: a highly available web platform in 18 LXC containers

My BTS SIO capstone: HAProxy, Varnish and three web servers for the corporate site, a LEMP shop with MariaDB replication, and redundant DNS. Measured at 1,884 requests per second with a web server down.

  • HAProxy
  • Varnish
  • MariaDB
  • BIND9
  • Proxmox

NexiCloud is the "fil rouge" of my second year of BTS SIO: a fictional hosting company whose corporate site is overloaded, whose client shops are not backed up, and whose developers version code by email. The brief was a proof of concept for moving all of it to a highly available, containerised platform. I built it on my Proxmox host: 18 LXC containers on their own bridge.

This is part 1 of 3: the architecture and the high availability. Part 2 covers CI/CD, Ansible, monitoring and backups; part 3 the security audit.

18LXC containers, Debian 13, unprivileged
1,884requests/s under load, 0 failures
100%availability with a web server killed mid-test
46/46automated acceptance checks passing

The brief, in one table

NexiCloud's problemWhat the PoC does
Corporate site falls over under traffic3 web servers behind HAProxy, Varnish cache in front
Shops run on one machine, no backupsLEMP split over 5 containers, MariaDB master → replica, daily backups
Code versioned by emailGitea + CI/CD pipeline to staging and production
Single DNS, single everythingPrimary and secondary DNS, health checks, boot ordering
No visibilityPrometheus + Grafana on every container, alerting
"Is it secure?"Per-container firewalls, TLS, anti-DDoS, written audit

Architecture

Everything lives on vmbr4, 172.16.1.0/24, a bridge dedicated to the project, with the host as gateway and NAT. Containers are grouped in four zones:

nexicloud-ha.svg
NexiCloud: 18 containers on vmbr4
NexiCloud: 18 containers on vmbr4
Text version
  visitors (LAN / VPN)
        │  :8080 / :8443   (host DNAT, nftables)
        ▼
 ┌──────────────── lb · 304 ────────────────┐
 │ HAProxy :80/:443  TLS · rate limit        │
 │    ├── www.*      → Varnish :6081 (cache) │
 │    │                 └→ HAProxy :8080 ──┐ │
 │    └── boutique.* → shop-nginx           │ │
 └──────────────────────────────────────────┘ │
   CORPORATE           round-robin, /health ◀─┘
   web1 · web2 · web3  (301 · 305 · 306)  nginx

   SHOP (LEMP)
   shop-nginx 307 ──FastCGI :9000──▶ shop-php 308 (WordPress + WooCommerce)
                                        │
                              db-master 310 ──GTID replication──▶ db-slave 311
                              phpmyadmin 309 (admins only)

   DEV / CI-CD                          INFRA
   gitea 302 → runner 312 → registry 313   bind9 300 ──zone transfer──▶ dns2 317
              └→ staging 314 → web1..3      ansible 303 · supervision 315 · backup 316
CTNameRoleSoftware
300 / 317bind9 / dns2Primary and secondary DNS for nexicloud.sioBIND 9.20
304lbSingle entry point: TLS, routing, load balancing, cache, rate limitingHAProxy 3.0, Varnish 7.7, fail2ban
301 / 305 / 306web1–3Corporate site, identical copiesnginx 1.26
307 / 308shop-nginx / shop-phpShop front and PHP executionnginx, PHP-FPM 8.4, WordPress, WooCommerce
310 / 311db-master / db-slaveAll writes / live replica, backup sourceMariaDB 11.8
309phpmyadminDatabase admin, restrictedApache, phpMyAdmin
302 · 312 · 313 · 314gitea · runner · registry · stagingGit, CI runner, image registry, pre-productionGitea, act_runner, Docker
303 · 315 · 316ansible · supervision · backupConfiguration, monitoring, backupsAnsible, Prometheus, Grafana, rsync

The front door: HAProxy

One container, lb, takes all traffic. HAProxy terminates TLS, routes on the Host header, rate-limits per source IP, and load-balances. Its configuration is generated by Ansible; here is the core of it.

haproxy.cfg.j2 (excerpt)
defaults
    mode http
    option forwardfor
    retries 3
    option redispatch                 # replay a failed request on another server
    retry-on conn-failure empty-response response-timeout

frontend fe_http
    bind *:80
    bind *:443 ssl crt /etc/haproxy/certs/nexicloud.pem alpn h2,http/1.1

    # the shop handles customer data: HTTPS only
    acl is_boutique hdr(host) -i -m beg boutique.
    http-request redirect scheme https code 301 if is_boutique !{ ssl_fc }

    use_backend be_boutique if is_boutique
    default_backend be_cache          # corporate site → Varnish

backend be_cache
    server varnish 127.0.0.1:6081 check

frontend fe_lb_internal               # Varnish comes back here on a miss
    bind 127.0.0.1:8080
    default_backend corporate_web

backend corporate_web
    balance roundrobin
    option httpchk GET /health
    default-server inter 2s fall 2 rise 2
    server web1 172.16.1.11:80 check
    server web2 172.16.1.15:80 check
    server web3 172.16.1.16:80 check

The interesting part is the loop: HAProxy → Varnish → HAProxy again → web servers. HAProxy is good at TLS and balancing, Varnish at caching; chaining them on localhost gives both without a second machine. A web server that fails two health checks two seconds apart is taken out; one that passes two is put back.

The cache

default.vcl.j2 (excerpt)
sub vcl_recv {
    if (req.url == "/health") { return (pass); }
    if (req.http.Cache-Control ~ "no-cache") { return (pass); }
    unset req.http.Cookie;               # static site: cookies only break caching
}
sub vcl_backend_response {
    set beresp.ttl   = 30s;
    set beresp.grace = 1h;               # keep serving stale pages if every web server is down
}
sub vcl_deliver {
    if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; }
}

Thirty seconds of cache is enough to absorb a traffic spike, and short enough that a deployment shows up quickly. The one-hour grace is a second safety net: if all three web servers were down at once, visitors would still get the last good page.

The shop: LEMP split in five

WordPress + WooCommerce, with each tier in its own container: nginx serves static files and passes PHP over FastCGI to PHP-FPM on another container, which talks to MariaDB. phpMyAdmin is there for admins and nobody else.

Two copies of WordPress

In the version I inherited, WordPress files had been copied separately onto the nginx and PHP containers, so uploads and plugins installed through PHP never appeared on the nginx side. The fix: one directory on the host, bind-mounted into both containers (mp0: /srv/nexicloud/boutique-www,mp=/var/www/html). One source of files, two readers.

MariaDB replication

Every write goes to db-master; db-slave replays them in real time using GTID-based replication. The replica is a warm standby, and it is where backups are taken, so dumps never lock or slow down the production database.

mariadb.conf.d · the master and the replica differ by three lines
[mysqld]
server-id     = 1            # 2 on the replica
log_bin       = mysql-bin
log-basename  = master       # slave on the replica
binlog_format = ROW
# replica only:
# read_only   = ON           # nothing but replication may write here
-- on the replica
CHANGE MASTER TO
  MASTER_HOST = '172.16.1.20',
  MASTER_USER = 'repl',
  MASTER_PASSWORD = '…',
  MASTER_USE_GTID = slave_pos;
START SLAVE;
SHOW SLAVE STATUS\G     -- Slave_IO_Running: Yes, Slave_SQL_Running: Yes, Seconds_Behind_Master: 0

Measured: a row written on the master is readable on the replica in under two seconds.

DNS without a single point of failure

bind9 is authoritative for nexicloud.sio and resolves for the internal network; dns2 receives the zone by transfer (allow-transfer limited to it). Every container lists both as nameservers. Stopping named on the primary: resolution kept working through the secondary, 9 ms per query.

Boot order: the bug nobody sees

When I took over the project, every container was stopped and none had a start order. On a cold start, the replica booted before the master, failed to connect (Connection refused) and replication stayed broken until someone noticed. Proxmox can fix this on its own:

OrderContainersWhy
1bind9, dns2Everything else resolves names at start-up
2 (+15 s)db-masterMust be accepting connections before anyone needs it
3db-slaveConnects to a master that is ready
4web, shop, dev, infra servicesNeed DNS and the database
5–6shop-nginx, lbFront ends last, so they never route to something still starting
pct set 300 --onboot 1 --startup order=1
pct set 310 --onboot 1 --startup order=2,up=15
pct set 311 --onboot 1 --startup order=3
pct set 304 --onboot 1 --startup order=6

Proving it

TestHowResult
Round-robincurl -sI -H 'Cache-Control: no-cache' http://172.16.1.14/ ×3X-Served-By: web1 → web2 → web3
Cachesame request twice, without no-cacheX-Cache: MISS then HIT
Loadsiege -c50 -t20S -b http://www.nexicloud.sio/1,884 req/s, 100%, 20 ms average
Web server dies under loadsiege running, pct stop 305100% availability, 0 failed requests
Replicationwrite on master, read on replica< 2 s
Primary DNS downsystemctl stop named on 300resolution via dns2

The web-server-down test is my favourite to demo: siege hammers the site, I stop a container, the HAProxy stats page turns one line red, Grafana shows the load shift, and siege still ends at 100%. option redispatch and retry-on replay the few requests that were in flight on the dying server.

Known limits

This is a proof of concept on one physical host, and I say so in the presentation:

  • HAProxy is a single point of failure. In production: two HAProxy nodes sharing a virtual IP with keepalived, on two Proxmox nodes.
  • Failover of the database is manual. The replica has all the data; promoting it is STOP SLAVE; RESET SLAVE ALL; and pointing WordPress at it. MaxScale or Galera would automate that.
  • The host is the ultimate SPOF. A three-node Proxmox cluster with HA is the real target.

Next: part 2, CI/CD, Ansible, monitoring and backups.