# 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"'; # 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.ke/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/* (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. 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. 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. ssl_certificate /etc/letsencrypt/live/vesuvio.pu.ac.ke/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/vesuvio.pu.ac.ke/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 the catch-all # 404 below. Drop this if the host root should stay empty. 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; } # /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; } }