📚 Encyclopedia

Servers & Hosting · updated 2026-11-02

nginx in front of Apache (TLS proxy on :8008)

nginxapachereverse-proxycertbotipv6vhost

On the Alma 9 server every site uses the same two-tier layout: nginx listens on 80/443, terminates TLS, redirects HTTP to HTTPS, and reverse-proxies to Apache (httpd) on 127.0.0.1:8008, which serves the files and runs PHP via php-fpm. Adopted 2026-03-15. Knowing which tier owns which job explains most "why is this broken" questions.

Who does what

Concern Owner
TLS certificates, HTTP to HTTPS 301 nginx (certbot --nginx)
Upload size limit (client_max_body_size) nginx (default 1M!)
Upstream timeout (proxy_read_timeout) nginx (default 60s)
gzip, long-lived cache headers for static paths nginx (per site)
DocumentRoot, rewrites, SPA fallback, aliases Apache vhost on *:8008
CORS headers Apache (works fine behind the proxy)
PHP php-fpm, called from Apache

Apache vhosts have no SSL directives at all. Old HTTP-only redirect vhosts were disabled because nginx owns redirects.

Files

Adding a new site

  1. Point DNS (A, and AAAA if you have one) at the server.
  2. Write the Apache vhost on :8008 and run apachectl configtest. A warning that the DocumentRoot does not exist is harmless if the first deploy has not run yet.
  3. Write the nginx server block that proxy_passes to http://127.0.0.1:8008 and sets Host, X-Forwarded-For and X-Forwarded-Proto.
  4. sudo certbot --nginx -d example.com -d www.example.com (auto-renew is already set up). For a <name>.jhampton.io site skip this step: point the 443 block at the wildcard certificate under /etc/letsencrypt/live/wildcard.jhampton.io/ instead (jhampton.io: one home domain, an index, and a wildcard certificate); copying an existing site's server/nginx-<name>.jhampton.io.conf (e.g. umlol's) gives a template that already includes the :80 → https redirect.
  5. systemctl reload httpd nginx, then curl both http:// (expect 301) and https://.

Apps that need to know the request was HTTPS (for Secure cookies, absolute URLs) must read X-Forwarded-Proto, because PHP only sees plain HTTP from nginx.

Exception: nginx-only sites (no Apache hop)

A static single-page app (Flutter web build) with a small PHP API does not need Apache. music.hampton.website (July 2026, conf /etc/nginx/conf.d/music.conf, modeled on forge.conf) is served entirely by nginx: - Static files straight from the docroot (/var/www/html/music/app/), with no-cache on entry points (index.html, flutter_bootstrap.js, service worker, manifest) and 1-year immutable caching on hashed assets, so deploys show up at once. - The PHP endpoint goes fastcgi_pass directly to the php-fpm upstream. php-fpm's pool runs as user apache, so any config file the script includes (for example a server-only s3_conf.php) must be readable by group apache, or PHP fails to load it. - Deploy: rsync the build to a staging dir in the home directory, then a sudo script rsyncs it into the docroot and runs restorecon (see SELinux file contexts and booleans on web servers).

How the layout was introduced (2026-03-15)

nginx was put in front originally so a webhook path could be proxied to a reverse SSH tunnel (claude-service on the desktop, port 9100), which Apache could not easily do under SELinux. The migration steps, useful if it ever has to be redone on a new box: - httpd.conf Listen 80 became Listen 127.0.0.1:8008; Listen 443 in ssl.conf was commented out; every <VirtualHost *:80>/*:443 became *:8008; all SSL directives were removed from Apache vhosts; the default server block in nginx.conf was disabled. - Port 8008 was chosen over 8080 because SELinux already labels it http_port_t; httpd_can_network_connect was already on and covers nginx too (same httpd_t domain). - Existing certbot renewal configs were switched to authenticator = nginx and installer = nginx. The nginx plugin edits the site's .conf in place (adds listen 443 ssl, cert paths and the redirect block); the Apache plugin used to create separate -le-ssl.conf files. No new file appearing is normal. - The nginx server block must exist before running certbot --nginx -d ... for a new site.

Gotchas

See also

Linked from

Sources: infra memory, hampton-website memory (hosting-layout), jah memory, plumb memory (deployment), hunsley memory (hhs-deployment), ~/dev memory (server-nginx-setup), hub memory (hub-index)