Procházet zdrojové kódy

fix(prod): take the catch-all out of Debian's conffile, brand the bare IP

The bare IP and any unknown hostname now answer a branded page with the
landing text and a 404 status: nothing is published there, and a 200
would say otherwise to every monitor and crawler that asks. The stock
"Welcome to nginx!" page is gone from the box's responses.

The way it was done first was wrong and is worth recording. I put the
include straight into /etc/nginx/sites-available/default, which belongs
to nginx-common and is a dpkg CONFFILE - so every later nginx upgrade
would have stopped and asked about a three-way merge, a cosmetic change
turning into an interactive prompt in the middle of an unattended
upgrade. It is restored byte-for-byte, dpkg --verify nginx-common prints
nothing again, and the catch-all lives in its own unowned file with the
packaged one left as shipped and simply not enabled. The stock page is
still on disk under /var/www/html, untouched and never served.

The failure mode is what makes this worth a rule rather than a note: the
edit works perfectly, and the damage only appears at an upgrade months
later, with nothing at the time to suggest anything is wrong.
fszontagh před 1 měsícem
rodič
revize
a057aa5f9f

+ 2 - 0
CLAUDE.md

@@ -211,6 +211,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **REMOVING A ROUTE DOES NOT CLOSE A PAGE THAT IS ALREADY OPEN, AND THE HALF-DEAD RESULT READS LIKE A SERVER FAULT.** Measured in a browser immediately after the reload: the HTML and `rapidoc-min.js` came from the browser's DISK CACHE so the title still rendered, while `openapi.json` went to the network and 404'd - leaving a page that looked alive and listed nothing. A cache-busting query string answered nginx's own 404, which is the real state. So verify a withdrawal with a URL the cache has never seen, and expect anyone who had the page open to meet a BROKEN docs page rather than an absent one.
   **THE ERROR PAGES ARE BRANDED NOW, AND ONE SETTING DECIDES WHETHER THAT IS COSMETIC OR BREAKING.** `/etc/nginx/snippets/branded-errors.conf` maps 403/404/500/502/503/504 to static pages under `/var/www/smartbotics-errors/_brand/`, styled from the design tokens read off smartbotics.ai (`--gradient-primary`, `--foreground`, `--radius`), bilingual EN/HU, with a dark-mode variant. **`proxy_intercept_errors` is OFF, which is the default, and MUST STAY OFF**: it is the single setting that would replace vectorapi's own `{"error":{"code":...}}` JSON with HTML and silently break every client that parses our errors. Verified after the change that an unauthenticated `/api/v1/version` still answers the JSON envelope, because the branding is only meant to cover the errors NGINX ITSELF raises. Everything the page needs is on local disk, so the 502 page still renders when the upstream it is reporting on is down - an error page that fetched its own assets through the proxy would be blank in exactly the case it exists for. The pages are `internal` (unreachable as paths); only the logo is not, since the browser must fetch it.
   **AN ERROR PAGE'S RELATIVE URL RESOLVES AGAINST THE REQUESTED PATH, NOT AGAINST THE ERROR PAGE'S OWN PATH, AND EVERY TEXT-BASED CHECK PASSES WHILE IT IS BROKEN.** The pages first carried `src="logo.png"`, which is correct relative to `/_brand/404.html` and is never what the browser resolves: nginx's internal redirect leaves the URL as the REQUEST, so the logo was fetched from `/logo.png`, or `/some/deep/logo.png`, and 404'd every time. curl said `status=404 type=text/html` and the body contained the brand name twice, so it looked finished. **It was a screenshot that found it** - the broken-image icon - which is the one check that could. A local preview had also passed, because the file happened to sit beside the HTML there, so the preview was testing a layout the server can never reproduce. Absolute `/_brand/logo.png` fixes it, and the test that proves it is a DEEP path, not the one the page was first opened at.
+  **EVERY nginx-RAISED ERROR ON THE BOX IS BRANDED NOW, AND THE CATCH-ALL IS OURS RATHER THAN DEBIAN'S.** The snippet is included by all four server blocks: both hostnames, the port-80 redirect and the catch-all. The bare IP and any unknown hostname answer a branded page carrying the landing text, with status **404** rather than 200, because nothing is published there and a 200 would tell every monitor and crawler otherwise. Verified afterwards that qdrant still answers its own JSON on `:6334` and the whole `/rag/` surface is untouched, which is the part that mattered: that hostname fronts a service that is not ours.
+  **NEVER EDIT A dpkg CONFFILE TO DO IT. `/etc/nginx/sites-available/default` belongs to nginx-common**, and a modified conffile makes every later nginx upgrade stop and ask about a three-way merge - a cosmetic change turning into an interactive prompt in the middle of an unattended upgrade. I edited it, the owner caught it, and it was restored byte-for-byte (`dpkg --verify nginx-common` prints nothing, which is the check). The catch-all now lives in `/etc/nginx/sites-available/smartbotics-catchall`, which no package owns, and the packaged `default` is left as shipped and simply not symlinked into `sites-enabled`; `/var/www/html/index.nginx-debian.html` is the same story, still on disk and never served. **`dpkg -S <file>` before touching anything under `/etc`** - and note the failure is invisible at the time, since the edit works perfectly until an upgrade months later.
   **Two traps met while doing it.** The half-written config was a BYTE COPY of the qdrant one with a single `server_name` changed, so it still carried full duplicate `qdrant-1` blocks on 443 and 80 and pointed at qdrant's port 6333 and qdrant's certificate - enabling that would have put conflicting server blocks on the live site and served a cert that covers neither name. And **the first request after `systemctl reload nginx` hit the old worker set and answered 404**, which read exactly like a broken location block; every path passed on a retry seconds later. Do not diagnose an nginx location from a request issued in the same breath as the reload.
 - **Prod's database binds `localhost`, not `0.0.0.0`** (`storage.bind_address`), which is why it is only reachable from vectorapi on the same box - correct, and worth knowing before wondering why a port-mapped copy refuses connections.
 - **`policy-rc.d` DOES NOT HOLD THE DATABASE PACKAGE. It blocks `invoke-rc.d`, and that postinst calls `systemctl` DIRECTLY.** Measured the hard way on 2026-10-12: a `policy-rc.d` returning 101 was in place, the pinned install ran at 18:21:12, and the service restarted anyway - the 2.17.2 first-boot migration ran to completion before the install command had even returned. **A hold point three consumers had been promised simply did not exist**, and that cost TWO separate things, not one. One consumer lost the chance to say "wait, a call is live" that they had explicitly been offered. **And because the install itself triggered the migration, the outage happened at 18:21 rather than in the 18:30 slot all three had approved** - it ran NINE MINUTES EARLY, outside the approved window, which is a governance failure distinct from the missing check. A consumer put that second point in the record; my own account had blurred it into the first, which understated it.

+ 18 - 5
packaging/nginx/README.md

@@ -14,12 +14,25 @@ The host is the source of truth; this is the backup and the review surface.
 | `branded-errors.conf` | `/etc/nginx/snippets/branded-errors.conf` |
 | `errors/_brand/*` | `/var/www/smartbotics-errors/_brand/` |
 | `qdrant-1.shop.static.shopcall.ai.conf` | `/etc/nginx/sites-available/qdrant-1.shop.static.shopcall.ai` |
-| `default.conf` | `/etc/nginx/sites-available/default` |
+| `smartbotics-catchall.conf` | `/etc/nginx/sites-available/smartbotics-catchall` |
 
-The last two are copied for recovery and review only. The old hostname also
-fronts **qdrant** on `142.93.100.6:6334`, which has nothing to do with this
-service, so change them on the host with that in mind. `default` is the
-catch-all a request to the bare IP or an unknown hostname lands on.
+The old hostname also fronts **qdrant** on `142.93.100.6:6334`, which has
+nothing to do with this service, so change it on the host with that in mind.
+
+## NEVER EDIT A PACKAGE CONFFILE
+
+`/etc/nginx/sites-available/default` belongs to **nginx-common** and is a dpkg
+CONFFILE. Editing it makes every later nginx upgrade stop and ask about a
+three-way merge, which is how a cosmetic change becomes an interactive prompt
+in the middle of an unattended upgrade. It was edited here once and restored;
+`dpkg --verify nginx-common` is the check, and it must print nothing.
+
+So the catch-all lives in `smartbotics-catchall`, which no package owns, and
+the packaged `default` is left byte-for-byte as shipped and simply not
+symlinked into `sites-enabled`. `/var/www/html/index.nginx-debian.html` is the
+same story: still on disk, never served. Before changing anything under
+`/etc/nginx`, run `dpkg -S <file>` and put the change in a file of our own if
+a package answers.
 
 All four server blocks across those two files include `branded-errors.conf`,
 so every nginx-raised error on this box is branded. Verified afterwards that

+ 0 - 96
packaging/nginx/default.conf

@@ -1,96 +0,0 @@
-##
-# You should look at the following URL's in order to grasp a solid understanding
-# of Nginx configuration files in order to fully unleash the power of Nginx.
-# https://www.nginx.com/resources/wiki/start/
-# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
-# https://wiki.debian.org/Nginx/DirectoryStructure
-#
-# In most cases, administrators will remove this file from sites-enabled/ and
-# leave it as reference inside of sites-available where it will continue to be
-# updated by the nginx packaging team.
-#
-# This file will automatically load configuration files provided by other
-# applications, such as Drupal or Wordpress. These applications will be made
-# available underneath a path with that package name, such as /drupal8.
-#
-# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
-##
-
-# Default server configuration
-#
-server {
-	listen 80 default_server;
-	listen [::]:80 default_server;
-
-	# SSL configuration
-	#
-	# listen 443 ssl default_server;
-	# listen [::]:443 ssl default_server;
-	#
-	# Note: You should disable gzip for SSL traffic.
-	# See: https://bugs.debian.org/773332
-	#
-	# Read up on ssl_ciphers to ensure a secure configuration.
-	# See: https://bugs.debian.org/765782
-	#
-	# Self signed certs generated by the ssl-cert package
-	# Don't use them in a production server!
-	#
-	# include snippets/snakeoil.conf;
-
-	root /var/www/html;
-
-	# Add index.php to the list if you are using PHP
-	index index.html index.htm index.nginx-debian.html;
-
-	server_name _;
-
-	# Branded error pages. This is the catch-all: a request to the bare IP
-	# or an unknown hostname lands here, so it is the most likely place a
-	# stranger meets us.
-	include /etc/nginx/snippets/branded-errors.conf;
-
-	location / {
-		# First attempt to serve request as file, then
-		# as directory, then fall back to displaying a 404.
-		try_files $uri $uri/ =404;
-	}
-
-	# pass PHP scripts to FastCGI server
-	#
-	#location ~ \.php$ {
-	#	include snippets/fastcgi-php.conf;
-	#
-	#	# With php-fpm (or other unix sockets):
-	#	fastcgi_pass unix:/run/php/php7.4-fpm.sock;
-	#	# With php-cgi (or other tcp sockets):
-	#	fastcgi_pass 127.0.0.1:9000;
-	#}
-
-	# deny access to .htaccess files, if Apache's document root
-	# concurs with nginx's one
-	#
-	#location ~ /\.ht {
-	#	deny all;
-	#}
-}
-
-
-# Virtual Host configuration for example.com
-#
-# You can move that to a different file under sites-available/ and symlink that
-# to sites-enabled/ to enable it.
-#
-#server {
-#	listen 80;
-#	listen [::]:80;
-#
-#	server_name example.com;
-#
-#	root /var/www/example.com;
-#	index index.html;
-#
-#	location / {
-#		try_files $uri $uri/ =404;
-#	}
-#}

+ 56 - 0
packaging/nginx/errors/_brand/landing.html

@@ -0,0 +1,56 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<meta name="robots" content="noindex,nofollow">
+<title>SmartBotics - API host</title>
+<style>
+:root{
+  --bg:#ffffff; --fg:#1f2937; --muted:#6b7280; --border:#e5e7eb; --radius:.75rem;
+  --grad:linear-gradient(135deg,hsl(193,100%,50%),hsl(262,83%,58%),hsl(310,100%,69%),hsl(25,95%,53%));
+  --shadow:0 10px 15px -3px hsla(262,83%,58%,.1),0 4px 6px -2px hsla(262,83%,58%,.05);
+}
+@media (prefers-color-scheme:dark){
+  :root{ --bg:hsl(225,12%,8%); --fg:#e5e7eb; --muted:#9aa3b2; --border:hsl(225,12%,18%);
+          --shadow:0 10px 15px -3px rgba(0,0,0,.5); }
+}
+*{box-sizing:border-box}
+html,body{height:100%}
+body{
+  margin:0; background:var(--bg); color:var(--fg);
+  font-family:Inter,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
+  display:flex; align-items:center; justify-content:center; padding:24px; line-height:1.55;
+}
+.bar{position:fixed;top:0;left:0;right:0;height:4px;background:var(--grad)}
+.card{
+  width:100%; max-width:560px; text-align:center;
+  border:1px solid var(--border); border-radius:var(--radius);
+  box-shadow:var(--shadow); padding:40px 32px; background:var(--bg);
+}
+.logo{width:200px;max-width:70%;height:auto;margin:0 auto 28px;display:block}
+.code{
+  font-size:64px; font-weight:800; line-height:1; margin:0 0 8px; letter-spacing:-.02em;
+  background:var(--grad); -webkit-background-clip:text; background-clip:text;
+  -webkit-text-fill-color:transparent; color:hsl(262,83%,58%);
+}
+h1{font-size:20px;font-weight:600;margin:0 0 14px}
+.lead{font-size:26px;font-weight:700;letter-spacing:-.01em;margin:0 0 14px}
+p{margin:0 0 10px;color:var(--muted);font-size:15px}
+p.hu{font-size:14px}
+.foot{margin-top:26px;padding-top:18px;border-top:1px solid var(--border);font-size:13px;color:var(--muted)}
+.foot a{color:inherit;text-decoration:none;border-bottom:1px solid var(--border)}
+@media (max-width:420px){ .card{padding:28px 20px} .code{font-size:48px} }
+</style>
+</head>
+<body>
+<div class="bar"></div>
+<main class="card">
+  <img class="logo" src="/_brand/logo.png" alt="SmartBotics" width="320" height="154">
+  <h1 class="lead">API host</h1>
+  <p>No service is published at this address.</p>
+  <p class="hu">Ezen a címen nem érhető el szolgáltatás.</p>
+  <div class="foot"><a href="https://smartbotics.ai/">smartbotics.ai</a></div>
+</main>
+</body>
+</html>

+ 30 - 0
packaging/nginx/smartbotics-catchall.conf

@@ -0,0 +1,30 @@
+# Catch-all: requests naming no hostname we serve - the bare IP, an unknown
+# name, a stale DNS record, a scanner dialling the address directly.
+#
+# This file exists so that Debian's /etc/nginx/sites-available/default never
+# has to be edited. That file is a dpkg CONFFILE owned by nginx-common, and a
+# modified conffile makes every future nginx upgrade stop and ask about a
+# three-way merge - a small tidy-up turning into an interactive prompt during
+# an unattended upgrade. It is left byte-for-byte as the package shipped it and
+# simply not symlinked into sites-enabled. Nothing here is package-owned, so
+# upgrades never touch it. The same rule applies to /var/www/html, which still
+# holds the stock Debian page: it is not edited, it is just never served.
+server {
+    listen 80 default_server;
+    listen [::]:80 default_server;
+    server_name _;
+
+    include /etc/nginx/snippets/branded-errors.conf;
+
+    # The root gets the landing text rather than the generic "not found", but
+    # still answers 404: nothing is published here, and a 200 would say
+    # otherwise to every monitor and crawler that asks.
+    location = / {
+        error_page 404 /_brand/landing.html;
+        return 404;
+    }
+
+    location / {
+        return 404;
+    }
+}