# nginx Install Instructions for the Test Host Written for: the owner, who places the config. Source: the Pi-Main session on `web1.slpsoftware.nl` (192.168.1.103), 2026-11-01, read-only and without sudo. `nginx -t` was not run; that happens at installation. The final commands with full paths go into the draft in the `server-ops` repository, for example `drafts/2026-11-xx-andreaslop-prerender/` with `README.md` and `andreaslop-test.conf`. The owner places it as `pi-main` with sudo, following that README and the checklist in `drafts/2026-10-20-hardening/README.md`. Nothing here has been carried out. The draft is requested separately, with the generated text. ## Checked on the server | Point | Finding | |---|---| | `map` and `$andreaslop_canonical` | No clash. The only other map in `/etc/nginx` is `$connection_upgrade` in `nginx.conf`. All `conf.d` files are included in `http` (`nginx.conf` line 38), so a map at the top of the file is at http level | | `root` | `/var/www/html` is a symlink to `/mnt/storage1/www/html/`; `/var/www/html/andreaslop-test` exists (`webadmin:www-data`, 775). The owner confirmed `DEPLOY_PATH_TEST` is `/var/www/html/andreaslop-test`, which equals this `root` | | gzip and headers from other vhosts | gzip is on nowhere, and `nginx.conf` has no http-level `add_header`. gzip in this server block changes no other site | | Default block | Since 2026-10-21, `/etc/nginx/conf.d/00-default.conf` answers an unknown host with 444. The generated header says so | | nginx 1.30.6 | Every directive in the sketch is standard there. `if` with only `return` at server level is safe | | `map` matching | Plain string keys in `map` compare case-insensitively, so `/over-mij ""` also matched `/Over-Mij` and blocked its redirect (found by the real nginx in CI). Canonical forms are therefore case-sensitive regex keys placed before the variant regexes; the first regex that matches wins and no loop arises. The draft must use the regenerated config | | `error_page` | Its internal redirect runs server-level rewrite and `if` again with `$uri=/404.html`. That matches no map rule. **Keep it so: no map rule may match `/404` or `/404.html`** | | Directories | `try_files $uri` matches files only, so `/assets` gives 404 | ## Installation Order: place the config, reload, and start the deploy right after: manually from the branch, or by merging. Do not leave a day in between. The new config with the old build gives 404 on `/over-mij`, and the old config with the new build shows the homepage there. A short mismatch is acceptable on test. ```bash # Backup outside conf.d: a *.conf backup in conf.d would be loaded by nginx sudo install -d -o root -g root -m 700 /mnt/storage1/backups/andreaslop-test-nginx sudo cp -p /etc/nginx/conf.d/andreaslop-test.conf /mnt/storage1/backups/andreaslop-test-nginx/andreaslop-test.conf.spa # Place (the current file is root:root 644) sudo install -o root -g root -m 644 /home/claude/server-ops/drafts//andreaslop-test.conf /etc/nginx/conf.d/andreaslop-test.conf sudo nginx -t && sudo systemctl reload nginx ``` If `nginx -t` fails, nginx does not reload. Put the backup back. Use reload first. Reload has not been tested separately on 1.30.6 on this Pi, because nginx was restarted after that update. If the new config does not work after the reload, `sudo systemctl restart nginx` is the fallback. ## Checks on the Pi The Pi-Main session can run these too, without sudo. They need the new build deployed. ```bash for p in / /over-mij /over-mij.html /over-mij/ /index.html /bestaat-niet /404 /robots.txt; do curl -s -o /dev/null -w "$p %{http_code} %{redirect_url}\n" -H 'Host: test.andreaslop.nl' http://127.0.0.1$p; done curl -s -o /dev/null -D - -H 'Host: test.andreaslop.nl' -H 'Accept-Encoding: gzip' --http1.0 http://127.0.0.1/ | grep -iE '^(HTTP|content-encoding|vary|cache-control|content-security)' ``` `--http1.0` is deliberate: that is how the proxy Pi talks to this Pi. Run the second command for one file in `/assets/` too. Expected: - `/` and `/over-mij` give 200. - `/over-mij.html`, `/over-mij/` and `/index.html` give 301 with a relative `Location`. - `/bestaat-niet` and `/404` give 404 with the content of `404.html`. - `/robots.txt` gives 200. - `Content-Encoding: gzip` and `Vary: Accept-Encoding` are present. - The security headers are also on the 404. - Assets have `immutable`. Also check that `andreaslop.nl`, `gitea.slpsoftware.nl` and phpMyAdmin still give 200. Then repeat the checks on `https://test.andreaslop.nl/` from outside. ## Rollback ```bash sudo cp -p /mnt/storage1/backups/andreaslop-test-nginx/andreaslop-test.conf.spa /etc/nginx/conf.d/andreaslop-test.conf sudo nginx -t && sudo systemctl reload nginx ``` Then deploy an old SPA build. ## Proxy Pi (192.168.1.102): the owner checks The proxy Pi handles TLS through certbot and forwards `test.andreaslop.nl` to `192.168.1.103:80`. The Pi-Main session has no access to it. Run `sudo nginx -T` and look for: | Look for | Why | |---|---| | `proxy_set_header Accept-Encoding ""` or similar | The backend then never gets a gzip request, and gzip here has no effect | | `proxy_http_version` | When unset it is 1.0; `gzip_http_version 1.0` in the new block is there for this | | `proxy_intercept_errors` or `error_page` | The proxy would replace `404.html` with its own error page | | Own `add_header`, especially HSTS, CSP, X-Frame-Options, Cache-Control | Double or conflicting headers. Two CSP headers are both enforced | | `proxy_cache` | An old SPA `index.html` could stay cached for `/over-mij` | | `proxy_redirect` | Could change the relative 301s | **Checked by the owner on 2026-11-01, reported through the Pi-Main session: no change needed on the proxy Pi.** The server block has `proxy_pass http://192.168.1.103` with Host, X-Forwarded-Proto, X-Forwarded-For and X-Real-IP, and no `proxy_http_version` (so HTTP/1.0 upstream), no change to `Accept-Encoding`, no `proxy_intercept_errors` and no `add_header`. At http level there is no gzip, `proxy_cache`, `add_header` or `proxy_buffering`. So `gzip_http_version 1.0` must stay in the new block, all headers and the 404 page come from the hosting Pi, and no cache holds old pages. `http2 on;` in the 443 block is an optional, separate improvement, out of scope for this feature. The proxy passes an already compressed response through unchanged. If the owner wants gzip for all sites, WordPress included, the proxy Pi is the place for that, and this block can keep its own. ## Points for the generated config - `add_header` in a location replaces all server-level `add_header`. Every location with its own `add_header` repeats the whole set, certainly `/assets/` (`immutable`), or it loses CSP and HSTS. A location without `add_header` inherits. `/assets/` carries one `Cache-Control`, not a second one. - `etag` stays on (the default), so `no-cache` revalidates cheaply. - The deploy must empty the target folder, or a removed page stays at 200. The `deploy-test` step already does this with `find -delete`. - `location = /robots.txt` overrides the build's `robots.txt`, which is right for test. Production must serve the real `robots.txt` and `sitemap.xml`. - `gzip_proxied any` does little here, since the proxy sets no `Via`, but it does no harm. `listen 80` on IPv4 is enough. ## Draft and Check on nginx 1.30.6 The Pi-Main session placed the draft in `server-ops` at `drafts/2026-11-01-andreaslop-prerender/` (commit 9c873bf), with `README.md` as step 11 of the owner's checklist. The config is a literal copy of commit b6d5a85e (sha256 `8ed373bb306e90b0...`, 168 lines, LF). Without root, it ran a copy of this file on nginx 1.30.6 with only `listen` and `root` changed, on 127.0.0.1:18080, with test pages, and stopped it afterwards. `nginx -t` on a separate test config reported `syntax is ok`; the bind on port 80 failed as an ordinary user, as expected. | Request | Result on 1.30.6 | |---|---| | `/`, `/over-mij`, `/over-mij?x=1`, `/soorten-fotoshoots`, `/soorten-fotoshoots/newborn` | 200 | | `/Over-Mij`, `/OVER-MIJ.HTML`, `/over-mij.html`, `/over-mij/` | 301 to `/over-mij`, relative, query kept | | `/index.html`, `/index` | 301 to `/` | | `/bestaat-niet`, `/404`, `/404.html`, `/assets/nope.js`, `/assets`, `/%5Cevil.example/` | 404 with the 404 page and security headers | | `//evil.example/` | 301 to `/evil.example`, relative, so no open redirect | | HTTP/1.0 with gzip accepted, on HTML and an asset | `Content-Encoding: gzip`, `Vary: Accept-Encoding`; the asset has `immutable` and the security headers | Not yet proven: the same file at its real path with `nginx -t` as root, and the checks through the proxy. Those follow at installation.