···293293 location /stub_status {
294294 stub_status;
295295 }
296296+ location / {
297297+ return 404;
298298+ }
296299 }
297300 ```
298301···378381- [x] nginx: enable cache
379382- [x] nginx: rate-limit
380383- [ ] nginx: get metrics
384384+385385+386386+387387+388388+---
389389+390390+nginx cors for constellation + small burst bump
391391+392392+```nginx
393393+upstream cozy_constellation {
394394+ server <tailnet ip>:6789; # bootes; ip so that we don't race on reboot with tailscale coming up, which nginx doesn't like
395395+ keepalive 16;
396396+}
397397+398398+server {
399399+ server_name constellation.microcosm.blue;
400400+401401+ proxy_cache cozy_zone;
402402+ proxy_cache_background_update on;
403403+ proxy_cache_key "$scheme$proxy_host$uri$is_args$args$http_accept";
404404+ proxy_cache_lock on; # make simlutaneous requests for the same uri wait for it to appear in cache instead of hitting origin
405405+ proxy_cache_lock_age 1s;
406406+ proxy_cache_lock_timeout 2s;
407407+ proxy_cache_valid 10s; # default -- should be explicitly set in the response headers
408408+ proxy_cache_valid any 2s; # non-200s default
409409+ proxy_read_timeout 5s;
410410+ proxy_send_timeout 15s;
411411+ proxy_socket_keepalive on;
412412+413413+ # take over cors responsibility from upsteram. `always` applies it to error responses.
414414+ proxy_hide_header 'Access-Control-Allow-Origin';
415415+ proxy_hide_header 'Access-Control-Allowed-Methods';
416416+ proxy_hide_header 'Access-Control-Allow-Headers';
417417+ add_header 'Access-Control-Allow-Origin' '*' always;
418418+ add_header 'Access-Control-Allow-Methods' 'GET' always;
419419+ add_header 'Access-Control-Allow-Headers' '*' always;
420420+421421+422422+ limit_req zone=cozy_ip_limit nodelay burst=150;
423423+ limit_req zone=cozy_global_limit burst=1800;
424424+ limit_req_status 429;
425425+426426+ location / {
427427+ proxy_pass http://cozy_constellation;
428428+ include proxy_params;
429429+ proxy_http_version 1.1;
430430+ proxy_set_header Connection ""; # for keepalive
431431+ }
432432+433433+434434+ listen 443 ssl; # managed by Certbot
435435+ ssl_certificate /etc/letsencrypt/live/constellation.microcosm.blue/fullchain.pem; # managed by Certbot
436436+ ssl_certificate_key /etc/letsencrypt/live/constellation.microcosm.blue/privkey.pem; # managed by Certbot
437437+ include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
438438+ ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
439439+440440+}
441441+442442+server {
443443+ if ($host = constellation.microcosm.blue) {
444444+ return 301 https://$host$request_uri;
445445+ } # managed by Certbot
446446+447447+448448+ server_name constellation.microcosm.blue;
449449+ listen 80;
450450+ return 404; # managed by Certbot
451451+}
452452+```
453453+454454+re-reading about `nodelay`, i should probably remove it -- nginx would then queue requests to upstream, but still service them at the configured limit. it's fine for my internet since the global limit isn't nodelay, but probably less "fair" to clients if there's contention around the global limit (earlier requests would get all of theirs serviced before later ones can get in the queue)
455455+456456+leaving it for now though.
457457+458458+459459+### nginx logs to prom
460460+461461+```bash
462462+curl -LO https://github.com/martin-helmich/prometheus-nginxlog-exporter/releases/download/v1.11.0/prometheus-nginxlog-exporter_1.11.0_linux_amd64.deb
463463+apt install ./prometheus-nginxlog-exporter_1.11.0_linux_amd64.deb
464464+systemctl enable prometheus-nginxlog-exporter.service
465465+466466+```
467467+468468+have it run as www-data (maybe not the best idea but...)
469469+file `/usr/lib/systemd/system/prometheus-nginxlog-exporter.service`
470470+set User under service and remove capabilities bounding
471471+472472+```systemd
473473+User=www-data
474474+#CapabilityBoundingSet=
475475+```
476476+477477+in `nginx.conf` in `http`:
478478+479479+```nginx
480480+log_format constellation_format "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\"";
481481+```
482482+483483+in `sites-available/constellation.microcosm.blue` in `server`:
484484+485485+```nginx
486486+# log format must match prometheus-nginx-log-exporter
487487+access_log /var/log/nginx/constellation-access.log constellation_format;
488488+```
489489+490490+config at `/etc/prometheus-nginxlog-exporter.hcl`
491491+492492+493493+494494+```bash
495495+systemctl start prometheus-nginxlog-exporter.service
496496+```