about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-07 14:03:02 +0000
committerPjotr <wrk@bosa.lan>2026-11-07 14:03:02 +0000
commit79fc027198dadfc55ddc13691f7f09deff012ff0 (patch)
treed88f527c431b15319a2e5aee3e73a979bce1f0c1
parentea2af939642cd7cc780becdcad5e3ab9b478ef26 (diff)
downloadgenenetwork4-79fc027198dadfc55ddc13691f7f09deff012ff0.tar.gz
etc: split the http redirect into its own server block
The installed copy merged certbot's port-80 redirect into the TLS block,
which makes that block an HTTP one (listen 80) -- so the /gn4 mount was
only reachable over plain HTTP and https://…/gn4 fell through to the
default server. The same redirect left inside a restored `listen 443 ssl`
block would point at itself, since hosts matching `$host` would be
redirected to the URL they already asked for.

So the port 80 block exists only for the redirect, and www is dropped
from server_name: the certificate's subjectAltName is only
vesuvio.pu.ac.ke, so https://www.<host> cannot be served until the
certificate covers it.

* etc/nginx-vesuvio.pu.ac.ke.conf (server): new listen-80 redirect block;
drop www from the TLS block's server_name.
-rw-r--r--etc/nginx-vesuvio.pu.ac.ke.conf19
1 files changed, 18 insertions, 1 deletions
diff --git a/etc/nginx-vesuvio.pu.ac.ke.conf b/etc/nginx-vesuvio.pu.ac.ke.conf
index 1971af2..c0aaf9f 100644
--- a/etc/nginx-vesuvio.pu.ac.ke.conf
+++ b/etc/nginx-vesuvio.pu.ac.ke.conf
@@ -31,9 +31,25 @@ log_format gn4 '$remote_addr - $remote_user [$time_local] "$request" '
 #   XAPIAN_DB_PATH=/path/to/xapian-index \
 #   genenetwork4
 
+# Port 80 exists only to send people to https. It must be its own server
+# block: merging this into the 443 block turns that block into an HTTP one
+# (listen 80) and the "if $host" redirect then points back at itself.
+# certbot --nginx rewrites this block in its own style; either is fine, as
+# long as the redirect does not live in the TLS block.
+server {
+    listen 80;
+    listen [::]:80;
+    server_name vesuvio.pu.ac.ke;
+
+    return 301 https://vesuvio.pu.ac.ke$request_uri;
+}
+
 server {
     listen 443 ssl;
     http2 on;                      # nginx >= 1.25.1; else: listen 443 ssl http2;
+    # www is deliberately absent: the certificate's subjectAltName is only
+    # vesuvio.pu.ac.ke, so https://www.<host> would fail verification. Add
+    # it here once the certificate covers it (`certbot -d www.… --expand`).
     server_name vesuvio.pu.ac.ke;
 
     # Point these at the real files; the Let's Encrypt layout is assumed.
@@ -49,7 +65,8 @@ server {
     access_log /var/log/nginx/gn4.access.log gn4;
     error_log  /var/log/nginx/gn4.error.log;
 
-    # Bare host: send people to the mount point rather than 404.
+    # Bare host: send people to the mount point rather than the catch-all
+    # 404 below. Drop this if the host root should stay empty.
     location = /   { return 302 /gn4/; }
     location = /gn4 { return 301 /gn4/; }