From 06a85946732da34404a3dee554c5fc6f7ecdaa84 Mon Sep 17 00:00:00 2001 From: pjotr Date: Tue, 1 Dec 2026 12:59:14 +0000 Subject: romeral --- README.md | 2 +- docs/nginx.md | 24 ++--- docs/www/operator-checklist.md | 3 +- etc/nginx-vesuvio.pu.ac.ke.conf | 221 ---------------------------------------- etc/nginx.conf | 221 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 +- 6 files changed, 233 insertions(+), 240 deletions(-) delete mode 100644 etc/nginx-vesuvio.pu.ac.ke.conf create mode 100644 etc/nginx.conf diff --git a/README.md b/README.md index ac8f28f..2f6c008 100644 --- a/README.md +++ b/README.md @@ -3011,7 +3011,7 @@ request body: length limit exceeded` before any handler runs. Two consequences worth knowing: - a proxy in front must allow at least as much - (`client_max_body_size 64m` in `etc/nginx-vesuvio.pu.ac.ke.conf`), or + (`client_max_body_size 64m` in `etc/nginx-*`), or it refuses first with a 413 the API never sees; - a request does not need to be that large. For covariates, prefer `{"case_attribute": "Sex"}` -- the server reads the attribute and diff --git a/docs/nginx.md b/docs/nginx.md index 14f93d0..8fbe2a0 100644 --- a/docs/nginx.md +++ b/docs/nginx.md @@ -6,10 +6,7 @@ token minted from `scripts/gn-auth-stub.py` (see "Authentication" below). `romeral.systemsgenetics.org` is the authoritative name (it is behind -Cloudflare); `https://vesuvio.pu.ac.ke/gn4/` still answers, and will until the -old links have aged out, so both names are in `server_name` and in one -certificate. Nothing below depends on which of the two is used, except the -examples, which use the canonical one. +Cloudflare). Three things separate this from "just proxy it": @@ -61,7 +58,7 @@ proxy being misconfigured. See docs/search-engines.md. server { listen 443 ssl; http2 on; - server_name romeral.systemsgenetics.org vesuvio.pu.ac.ke; + server_name romeral.systemsgenetics.org; ssl_certificate /etc/nginx/ssl/romeral.systemsgenetics.org.pem; ssl_certificate_key /etc/nginx/ssl/romeral.systemsgenetics.org.key; @@ -128,8 +125,6 @@ server { ### The access log, and who is using the API -The format in `etc/nginx-vesuvio.pu.ac.ke.conf` records the caller's -identity, which the API sends back as a response header: ```nginx log_format gn4 '$remote_addr - $remote_user [$time_local] "$request" ' @@ -173,14 +168,13 @@ certbot-managed `server` block for this hostname) and reload; grep the error log for `conflicting server name` after any change to the vhost set. -For the `romeral.systemsgenetics.org/gn4` deployment as configured, -[`etc/nginx-vesuvio.pu.ac.ke.conf`](../etc/nginx-vesuvio.pu.ac.ke.conf) is -the same thing as a complete, drop-in file -- TLS, log format, the `/gn4` -redirect, and the `/get-test-token` refusal. `/compute/*` (R/qtl, GEMMA) -is proxied and gated on a valid token, at the cost of letting any token -holder name server-side paths for R and gemma to read — the operator -checklist in [`docs/www/operator-checklist.md`](www/operator-checklist.md) -covers that trade, what the box needs installed, and how to re-block it. +For the `romeral.systemsgenetics.org/gn4` deployment as configured, and is the +same thing as a complete, drop-in file -- TLS, log format, the `/gn4` redirect, +and the `/get-test-token` refusal. `/compute/*` (R/qtl, GEMMA) is proxied and +gated on a valid token, at the cost of letting any token holder name +server-side paths for R and gemma to read — the operator checklist in +[`docs/www/operator-checklist.md`](www/operator-checklist.md) covers that +trade, what the box needs installed, and how to re-block it. `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 diff --git a/docs/www/operator-checklist.md b/docs/www/operator-checklist.md index 400b383..f5408e7 100644 --- a/docs/www/operator-checklist.md +++ b/docs/www/operator-checklist.md @@ -6,8 +6,7 @@ runs the deployment: what has to stay off the public surface, how tokens are issued without gn-auth, and what is knowingly exposed. The reference deployment is `https://romeral.systemsgenetics.org/gn4/` proxied by -nginx to `127.0.0.1:3000` — see [`../nginx.md`](../nginx.md) and -[`../../etc/nginx-vesuvio.pu.ac.ke.conf`](../../etc/nginx-vesuvio.pu.ac.ke.conf). +nginx to `127.0.0.1:3000` — see [`../nginx.md`](../nginx.md). ``` nginx 443 / 80 public; TLS; /gn4/ -> 127.0.0.1:3000 diff --git a/etc/nginx-vesuvio.pu.ac.ke.conf b/etc/nginx-vesuvio.pu.ac.ke.conf deleted file mode 100644 index eb74500..0000000 --- a/etc/nginx-vesuvio.pu.ac.ke.conf +++ /dev/null @@ -1,221 +0,0 @@ -# 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 ' - 'user=$upstream_http_x_gn4_user ' - 'ua="$http_user_agent"'; - -# Cloudflare fronts romeral.systemsgenetics.org, so the peer nginx sees is an -# edge address. Trust the edge to name the client, from the published ranges -# only (https://www.cloudflare.com/ips/), or every log line and every -# per-address rule -- limit_conn above all -- would count Cloudflare, not the -# visitor. -set_real_ip_from 173.245.48.0/20; set_real_ip_from 103.21.244.0/22; -set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; -set_real_ip_from 141.101.64.0/18; set_real_ip_from 108.162.192.0/18; -set_real_ip_from 190.93.240.0/20; set_real_ip_from 188.114.96.0/20; -set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; -set_real_ip_from 162.158.0.0/15; set_real_ip_from 104.16.0.0/13; -set_real_ip_from 104.24.0.0/14; set_real_ip_from 172.64.0.0/13; -set_real_ip_from 131.0.72.0/22; -set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; -set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; -set_real_ip_from 2405:8100::/32; set_real_ip_from 2a06:98c0::/29; -set_real_ip_from 2c0f:f248::/32; -real_ip_header CF-Connecting-IP; - -# The root location holds a request open (limit_conn below caps how many), and -# its zone is declared in the http block: on vesuvio that is line 43 of -# /etc/nginx/nginx.conf -- -# limit_conn_zone $binary_remote_addr zone=gn4_root:1m; -# A host installing this file without that line must add it, or `nginx -t' -# fails on the unknown zone; adding it twice is a duplicate-zone error. -# -# Uncomment with the limit_req line inside the location below. -# limit_req_zone $binary_remote_addr zone=gn4_per_ip:10m rate=20r/s; - -# Two names, one site: romeral.systemsgenetics.org is authoritative (it is -# behind Cloudflare) and vesuvio.pu.ac.ke is the old name, kept answering until the -# published links have aged out. One certificate must cover BOTH: -# -# sudo certbot certonly --webroot -w /var/www/html \ -# -d romeral.systemsgenetics.org -d vesuvio.pu.ac.ke --cert-name vesuvio.pu.ac.ke --expand -# -# (`--cert-name` stays vesuvio.pu.ac.ke because that is where the live certificate -# lives; the name is historical, the subjectAltNames are what matter. Do not -# use `certbot --nginx`: it inserts its own :443 block for the name it is -# expanding, and that block shadows this one.) -# -# and it must stay that way at renewal (certbot renew keeps the names it was -# asked for). Do not let certbot add a second :443 block for one name: nginx -# serves a request from the first matching block, so the new one shadows this -# one, and a redirect left in it makes the site redirect to itself. -# Cloudflare forwards :80 to this origin, which is why the ACME path below is -# answered there before the redirect. - -# nginx: https://romeral.systemsgenetics.org/gn4/ -> genenetwork4 on 127.0.0.1:3000 -# (and https://vesuvio.pu.ac.ke/gn4/, the old name, which keeps answering) -# -# 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/* (R/qtl, GEMMA) 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 \ -# SEARCH_ENGINE=native \ -# 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. -# Port 80 exists only to send people to https, and to answer ACME challenges -# (certbot renews over :80, which Cloudflare forwards to this origin). It must -# be its own server block: merging it into the :443 block turns that block into -# an HTTP one and the redirect then points back at itself. -server { - listen 80; - listen [::]:80; - server_name romeral.systemsgenetics.org vesuvio.pu.ac.ke; - - # ${host} preserves the name the visitor used; a hardcoded name sends - # the canonical name's visitors to the old one and vice versa. - location /.well-known/acme-challenge/ { root /var/www/html; } - location / { return 301 https://$host$request_uri; } -} - -# One TLS server for both names. The certificate must cover both (see the -# certbot line in this file's header comment); certbot --nginx otherwise -# inserts a second :443 block for the new name, and because nginx takes the -# first block that matches a server_name, that block shadows this one -- -# which is exactly how "it redirects to itself forever" happened once. -server { - listen 443 ssl; - listen [::]:443 ssl; - http2 on; # nginx >= 1.25.1; else: listen 443 ssl http2; - server_name romeral.systemsgenetics.org vesuvio.pu.ac.ke; - - ssl_certificate /etc/letsencrypt/live/vesuvio.pu.ac.ke/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/vesuvio.pu.ac.ke/privkey.pem; - include /etc/letsencrypt/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; - 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; - - # The bare host answers nothing at all -- on either name, and through - # Cloudflare, which turns a held request into its own 524 after about 100 - # seconds. /gn4/ is the interface; a visit to the hostname is not an - # invitation to look around. proxy_pass points at TEST-NET-1 (RFC 5737), - # which is never routed, so the connect attempt goes nowhere and the - # client gives up first; the 300s timeouts are the backstop, not the - # intent. `return 444' is the cheaper alternative if holding sockets ever - # matters: it closes the connection with no reply. - location = / { - proxy_pass http://192.0.2.1:9; - proxy_connect_timeout 300s; - proxy_read_timeout 300s; - proxy_send_timeout 300s; - proxy_next_upstream off; - limit_conn gn4_root 4; - access_log off; - error_log /dev/null emerg; - } - - # ACME is answered here too, not only on :80: Cloudflare's "Always Use - # HTTPS" redirects the challenge to this port, and a renewal that lands - # here must not fall through to the 404 below. - location /.well-known/acme-challenge/ { root /var/www/html; } - - 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; } - - # /compute/* is proxied: R/qtl and GEMMA are part of the service, - # gated on a valid token like every other endpoint. Be aware of - # what that means -- these handlers take *server-side file paths* - # (genotype_file, snps_file) and run R/gemma on them, so any - # token holder can ask the server to read its own filesystem. - # See docs/www/operator-checklist.md; to take compute away again, - # restore: - # location = /gn4/compute { return 403; } - # location /gn4/compute/ { return 403; } - - # /compute/* is synchronous: 16-20s on the small BXD fixtures, - # minutes on real datasets, and ravanan-over-Slurm measured 158s - # with Slurm's default scheduler interval. nginx's 60s default - # would return 504 while the server carried on working, so raise - # these. - proxy_connect_timeout 10; - proxy_read_timeout 3600; - proxy_send_timeout 3600; - - # nginx's 1m default is far below what the API accepts: a - # /compute/* request carries one value per individual plus up to - # eight covariates, and /plot/* is posted a whole mapping result. - # Keep this at least as large as the application's own 64 MiB - # limit (BODY_LIMIT_BYTES in src/lib.rs), or nginx refuses first - # with a 413 the API never sees. - client_max_body_size 64m; - - # 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; } -} diff --git a/etc/nginx.conf b/etc/nginx.conf new file mode 100644 index 0000000..c13ca80 --- /dev/null +++ b/etc/nginx.conf @@ -0,0 +1,221 @@ +# 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 ' + 'user=$upstream_http_x_gn4_user ' + 'ua="$http_user_agent"'; + +# Cloudflare fronts romeral.systemsgenetics.org, so the peer nginx sees is an +# edge address. Trust the edge to name the client, from the published ranges +# only (https://www.cloudflare.com/ips/), or every log line and every +# per-address rule -- limit_conn above all -- would count Cloudflare, not the +# visitor. +set_real_ip_from 173.245.48.0/20; set_real_ip_from 103.21.244.0/22; +set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; +set_real_ip_from 141.101.64.0/18; set_real_ip_from 108.162.192.0/18; +set_real_ip_from 190.93.240.0/20; set_real_ip_from 188.114.96.0/20; +set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; +set_real_ip_from 162.158.0.0/15; set_real_ip_from 104.16.0.0/13; +set_real_ip_from 104.24.0.0/14; set_real_ip_from 172.64.0.0/13; +set_real_ip_from 131.0.72.0/22; +set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; +set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; +set_real_ip_from 2405:8100::/32; set_real_ip_from 2a06:98c0::/29; +set_real_ip_from 2c0f:f248::/32; +real_ip_header CF-Connecting-IP; + +# The root location holds a request open (limit_conn below caps how many), and +# its zone is declared in the http block: on vesuvio that is line 43 of +# /etc/nginx/nginx.conf -- +# limit_conn_zone $binary_remote_addr zone=gn4_root:1m; +# A host installing this file without that line must add it, or `nginx -t' +# fails on the unknown zone; adding it twice is a duplicate-zone error. +# +# Uncomment with the limit_req line inside the location below. +# limit_req_zone $binary_remote_addr zone=gn4_per_ip:10m rate=20r/s; + +# Two names, one site: romeral.systemsgenetics.org is authoritative (it is +# behind Cloudflare) and vesuvio. is the old name, kept answering until the +# published links have aged out. One certificate must cover BOTH: +# +# sudo certbot certonly --webroot -w /var/www/html \ +# -d romeral.systemsgenetics.org -d vesuvio. --cert-name vesuvio. --expand +# +# (`--cert-name` stays vesuvio. because that is where the live certificate +# lives; the name is historical, the subjectAltNames are what matter. Do not +# use `certbot --nginx`: it inserts its own :443 block for the name it is +# expanding, and that block shadows this one.) +# +# and it must stay that way at renewal (certbot renew keeps the names it was +# asked for). Do not let certbot add a second :443 block for one name: nginx +# serves a request from the first matching block, so the new one shadows this +# one, and a redirect left in it makes the site redirect to itself. +# Cloudflare forwards :80 to this origin, which is why the ACME path below is +# answered there before the redirect. + +# nginx: https://romeral.systemsgenetics.org/gn4/ -> genenetwork4 on 127.0.0.1:3000 +# (and https://vesuvio./gn4/, the old name, which keeps answering) +# +# 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/* (R/qtl, GEMMA) 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 \ +# SEARCH_ENGINE=native \ +# 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. +# Port 80 exists only to send people to https, and to answer ACME challenges +# (certbot renews over :80, which Cloudflare forwards to this origin). It must +# be its own server block: merging it into the :443 block turns that block into +# an HTTP one and the redirect then points back at itself. +server { + listen 80; + listen [::]:80; + server_name romeral.systemsgenetics.org vesuvio.; + + # ${host} preserves the name the visitor used; a hardcoded name sends + # the canonical name's visitors to the old one and vice versa. + location /.well-known/acme-challenge/ { root /var/www/html; } + location / { return 301 https://$host$request_uri; } +} + +# One TLS server for both names. The certificate must cover both (see the +# certbot line in this file's header comment); certbot --nginx otherwise +# inserts a second :443 block for the new name, and because nginx takes the +# first block that matches a server_name, that block shadows this one -- +# which is exactly how "it redirects to itself forever" happened once. +server { + listen 443 ssl; + listen [::]:443 ssl; + http2 on; # nginx >= 1.25.1; else: listen 443 ssl http2; + server_name romeral.systemsgenetics.org vesuvio.; + + ssl_certificate /etc/letsencrypt/live/vesuvio/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/vesuvio/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + 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; + + # The bare host answers nothing at all -- on either name, and through + # Cloudflare, which turns a held request into its own 524 after about 100 + # seconds. /gn4/ is the interface; a visit to the hostname is not an + # invitation to look around. proxy_pass points at TEST-NET-1 (RFC 5737), + # which is never routed, so the connect attempt goes nowhere and the + # client gives up first; the 300s timeouts are the backstop, not the + # intent. `return 444' is the cheaper alternative if holding sockets ever + # matters: it closes the connection with no reply. + location = / { + proxy_pass http://192.0.2.1:9; + proxy_connect_timeout 300s; + proxy_read_timeout 300s; + proxy_send_timeout 300s; + proxy_next_upstream off; + limit_conn gn4_root 4; + access_log off; + error_log /dev/null emerg; + } + + # ACME is answered here too, not only on :80: Cloudflare's "Always Use + # HTTPS" redirects the challenge to this port, and a renewal that lands + # here must not fall through to the 404 below. + location /.well-known/acme-challenge/ { root /var/www/html; } + + 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; } + + # /compute/* is proxied: R/qtl and GEMMA are part of the service, + # gated on a valid token like every other endpoint. Be aware of + # what that means -- these handlers take *server-side file paths* + # (genotype_file, snps_file) and run R/gemma on them, so any + # token holder can ask the server to read its own filesystem. + # See docs/www/operator-checklist.md; to take compute away again, + # restore: + # location = /gn4/compute { return 403; } + # location /gn4/compute/ { return 403; } + + # /compute/* is synchronous: 16-20s on the small BXD fixtures, + # minutes on real datasets, and ravanan-over-Slurm measured 158s + # with Slurm's default scheduler interval. nginx's 60s default + # would return 504 while the server carried on working, so raise + # these. + proxy_connect_timeout 10; + proxy_read_timeout 3600; + proxy_send_timeout 3600; + + # nginx's 1m default is far below what the API accepts: a + # /compute/* request carries one value per individual plus up to + # eight covariates, and /plot/* is posted a whole mapping result. + # Keep this at least as large as the application's own 64 MiB + # limit (BODY_LIMIT_BYTES in src/lib.rs), or nginx refuses first + # with a 413 the API never sees. + client_max_body_size 64m; + + # 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; } +} diff --git a/src/lib.rs b/src/lib.rs index bf1047b..2a2b062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -344,7 +344,7 @@ pub fn app() -> Router { // with axum's own plain-text 413 before any handler sees it, so // the limit has to sit above what the API accepts. nginx's // client_max_body_size must be at least as large (64m in - // etc/nginx-vesuvio.pu.ac.ke.conf), or it refuses first. + // etc/nginx.conf), or it refuses first. .layer(axum::extract::DefaultBodyLimit::max(BODY_LIMIT_BYTES)) // Assigns each request an x-request-id (if the client didn't // already send one) and copies it onto the response, so it can be -- cgit 1.4.1