about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-07 13:36:47 +0000
committerPjotr <wrk@bosa.lan>2026-11-07 13:38:53 +0000
commitf21ab7d46df904ece47ba59f1beba09515b59e58 (patch)
tree3c119d06542f6251fe9b987b4d184160a41bef0b
parentbab842660f592122109dca8520578c0fd6cd576d (diff)
downloadgenenetwork4-f21ab7d46df904ece47ba59f1beba09515b59e58.tar.gz
etc: drop-in nginx config for vesuvio.pu.ac.uk/gn4
docs/nginx.md explained the pieces; this is the assembled file for the
deployment actually being set up, so it can be reviewed and installed
without stitching anything together. It lives in etc/ rather than
docs/, being deployable configuration rather than prose.

It refuses /compute/*, which the README-based template did not: those
endpoints take server-side file paths and run gemma/ravanan/R on them,
so any token holder able to reach them can read the box -- the operator
checklist in docs/www/ai-instruction.md already said to keep them on the
internal listener, and this is that rule where it belongs.

* etc/nginx-vesuvio.pu.ac.uk.conf: new file. TLS, http2, log format
carrying x-request-id, / and /gn4 redirects, proxy_pass with the
prefix-stripping trailing slash, raised timeouts, sub_filter rewriting
of href/next/spec_url/type, and 403/404 refusals for /compute/ and
/get-test-token.
* docs/nginx.md: point at it, and say why /compute/ is refused.
-rw-r--r--docs/nginx.md9
-rw-r--r--etc/nginx-vesuvio.pu.ac.uk.conf121
2 files changed, 130 insertions, 0 deletions
diff --git a/docs/nginx.md b/docs/nginx.md
index 43658d3..cf59152 100644
--- a/docs/nginx.md
+++ b/docs/nginx.md
@@ -110,6 +110,15 @@ server {
 }
 ```
 
+For the `vesuvio.pu.ac.uk/gn4` deployment as configured,
+[`etc/nginx-vesuvio.pu.ac.uk.conf`](../etc/nginx-vesuvio.pu.ac.uk.conf) is
+the same thing as a complete, drop-in file -- TLS, log format, the `/gn4`
+redirect, and the `/compute/` and `/get-test-token` refusals. Note that
+it refuses `/compute/*`: those endpoints take server-side file paths, so
+they belong on the internal listener only (see the operator checklist in
+[`docs/www/ai-instruction.md`](www/ai-instruction.md)); drop the two
+`location` lines only if every token holder may read the server's files.
+
 `http2 on;` needs nginx >= 1.25.1; on older versions use `listen 443
 ssl http2;`. The block above (minus the `ssl_*` lines and the TLS
 listener) is tested against nginx 1.28: `nginx -t` accepts it, and with
diff --git a/etc/nginx-vesuvio.pu.ac.uk.conf b/etc/nginx-vesuvio.pu.ac.uk.conf
new file mode 100644
index 0000000..e57e4cf
--- /dev/null
+++ b/etc/nginx-vesuvio.pu.ac.uk.conf
@@ -0,0 +1,121 @@
+# These are http-level directives, and nginx wants them before the server
+# block that uses them. Both are legal in a conf.d snippet for that reason.
+log_format gn4 '$remote_addr - $remote_user [$time_local] "$request" '
+               '$status $body_bytes_sent rt=$request_time '
+               'rid=$upstream_http_x_request_id '
+               'ua="$http_user_agent"';
+
+# Uncomment with the limit_req line inside the location below.
+# limit_req_zone $binary_remote_addr zone=gn4_per_ip:10m rate=20r/s;
+
+# nginx: https://vesuvio.pu.ac.uk/gn4/ -> genenetwork4 on 127.0.0.1:3000
+#
+# Drop into /etc/nginx/conf.d/ (included from inside nginx's http block) or
+# paste the server block into /etc/nginx/sites-enabled/. The genenetwork4
+# side, and the reasoning behind every directive here, are in
+# docs/nginx.md; the summary is:
+#
+#   * proxy_pass has a trailing slash, which is what turns /gn4/species
+#     into /species upstream. Without it every request 404s.
+#   * /compute/* runs for minutes inside one request, so the read and send
+#     timeouts are raised well past nginx's 60s default.
+#   * the responses carry root-relative links ("href":"/groups"), so
+#     sub_filter puts /gn4 back on the four keys that hold one.
+#   * /get-test-token is refused here and not registered upstream either.
+#
+# Start genenetwork4 with (see docs/nginx.md):
+#   GENENETWORK4_BIND=127.0.0.1 GENENETWORK4_PORT=3000 \
+#   GENENETWORK4_TEST_TOKEN=false \
+#   AUTH_SERVER_URL=http://127.0.0.1:8081/ \
+#   SQL_URI=mysql://webqtlout:webqtlout@127.0.0.1/db_webqtl \
+#   XAPIAN_DB_PATH=/path/to/xapian-index \
+#   genenetwork4
+
+server {
+    listen 443 ssl;
+    http2 on;                      # nginx >= 1.25.1; else: listen 443 ssl http2;
+    server_name vesuvio.pu.ac.uk;
+
+    # Point these at the real files; the Let's Encrypt layout is assumed.
+    ssl_certificate     /etc/letsencrypt/live/vesuvio.pu.ac.uk/fullchain.pem;
+    ssl_certificate_key /etc/letsencrypt/live/vesuvio.pu.ac.uk/privkey.pem;
+    ssl_protocols TLSv1.2 TLSv1.3;
+    ssl_session_cache shared:gn4_ssl:10m;
+    ssl_session_timeout 1h;
+    # add_header Strict-Transport-Security "max-age=31536000" always;
+
+    server_tokens off;
+
+    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.
+    location = /   { return 302 /gn4/; }
+    location = /gn4 { return 301 /gn4/; }
+
+    location /gn4/ {
+        proxy_pass http://127.0.0.1:3000/;
+
+        proxy_set_header Host              $host;
+        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_set_header X-Real-IP         $remote_addr;
+
+        # genenetwork4 refuses proxied requests on its token-minting route
+        # (these headers are what makes it "proxied"), and the route is off
+        # upstream; this is the third, independent refusal.
+        location = /gn4/get-test-token { return 404; }
+
+        # POST /compute/* takes *server-side file paths* (genotype_file,
+        # snps_file) and runs gemma/ravanan/R on them, so with any valid
+        # token it is an arbitrary-read and -execution surface. The
+        # operator checklist in docs/www/ai-instruction.md says keep it on
+        # the internal listener; this is that rule in nginx. Drop these two
+        # lines only if every token holder may read the server's files.
+        location = /gn4/compute { return 403; }
+        location /gn4/compute/  { return 403; }
+
+        # Only matters if the /compute/ block below is removed: those
+        # endpoints are synchronous (16-20s on the small BXD fixtures,
+        # minutes on real datasets, ravanan-over-Slurm measured 158s with
+        # Slurm's default scheduler interval), and nginx's 60s default
+        # would 504 while the server carried on working. Harmless
+        # otherwise.
+        proxy_connect_timeout 10;
+        proxy_read_timeout    3600;
+        proxy_send_timeout    3600;
+
+        # Small JSON bodies, but a long /compute/rqtl sample list outgrows
+        # nginx's 1m default.
+        client_max_body_size 10m;
+
+        # No streaming: /compute/*/status/{run_id} is polled and returns
+        # accumulated lines as JSON, so buffering stays at its default.
+
+        # Root-relative links in JSON, put back under /gn4. Both spellings
+        # of each key: serde output is compact ("href":"/"), pretty-printed
+        # JSON and the request-shape examples are not. The envelope's
+        # "next":[ array cannot match a "next":"/ filter, so only href
+        # values are rewritten there.
+        sub_filter_types application/json;
+        sub_filter_once off;
+        sub_filter '"href":"/'        '"href":"/gn4/';
+        sub_filter '"spec_url":"/'    '"spec_url":"/gn4/';
+        sub_filter '"type":"/errors'  '"type":"/gn4/errors';
+        sub_filter '"next":"/'        '"next":"/gn4/';
+        sub_filter '"href": "/'       '"href": "/gn4/';
+        sub_filter '"spec_url": "/'   '"spec_url": "/gn4/';
+        sub_filter '"type": "/errors' '"type": "/gn4/errors';
+        sub_filter '"next": "/'       '"next": "/gn4/';
+
+        # Optional per-IP rate limiting. Uncomment together with the
+        # limit_req_zone at the top of this file; 429 (not nginx's
+        # default 503) is what the API's clients are told to expect.
+        # limit_req zone=gn4_per_ip burst=40 nodelay;
+        # limit_req_status 429;
+    }
+
+    # Nothing else on this host is served by genenetwork4, so say so
+    # rather than leaving whatever the default root is.
+    location / { return 404; }
+}