Keep nginx serving through a stalled worker, and gate Gitea's crawler targets
On 2026-10-19 nginx's only worker stalled for 4.6 hours. The master kept the container "Up" and the tunnel stayed connected, so nothing noticed, while every request timed out in the TLS handshake. - worker_processes auto in the production and dev configs, so one stuck worker no longer takes the whole site down. - A /nginx-health endpoint on :80 in all three configs, answered by nginx and unlogged, and a compose healthcheck on it. - autoheal is back (retired 2026-10-01), pinned by digest, with no network, restarting only containers labelled autoheal=true: just nginx. - Gitea's commit-pinned views, archives and compare pages go through the site admin gate. A swarm of 103k IPs made 129k requests to them in two days, 89% in those shapes; the branch views stay public for the CV links. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -36,6 +36,15 @@
|
||||
# (which carry the security headers), the `graphql` rate-limit zone and its
|
||||
# location, and the limit_req_zone declarations the shared routes refer to.
|
||||
# =============================================================================
|
||||
|
||||
# One worker per CPU. Unset, nginx runs a single worker, and on 2026-10-19 that
|
||||
# one worker stalled for 4.6 hours: the master kept the container "Up" and the
|
||||
# tunnel stayed connected, but every request timed out in the TLS handshake.
|
||||
# With several workers a stuck one only loses the connections it holds; the
|
||||
# others keep accepting. The healthcheck in docker-compose.yml (and autoheal
|
||||
# restarting on it) covers the case where they all stall.
|
||||
worker_processes auto;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
@@ -179,6 +188,15 @@ http {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
# The container healthcheck's target (docker-compose.yml). Answered by
|
||||
# nginx itself, so it measures whether a worker is serving and nothing
|
||||
# upstream. Unlogged, or it would put a line in the payload log every
|
||||
# 30s. Every config's default :80 server has one, setup and dev too.
|
||||
location = /nginx-health {
|
||||
access_log off;
|
||||
return 204;
|
||||
}
|
||||
|
||||
# Redirect everything else to HTTPS
|
||||
location / {
|
||||
return 301 https://www.$DOMAIN$request_uri;
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
# annotated in nginx_routes.conf.template; the rate-limit reasoning is in
|
||||
# nginx.conf.template.
|
||||
# =============================================================================
|
||||
|
||||
# As in production; why is in nginx.conf.template.
|
||||
worker_processes auto;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
@@ -89,6 +93,13 @@ http {
|
||||
listen 80;
|
||||
server_name $DOMAIN www.$DOMAIN;
|
||||
|
||||
# The container healthcheck's target; see nginx.conf.template. Only in
|
||||
# this block, as in production, where it sits in the :80 server too.
|
||||
location = /nginx-health {
|
||||
access_log off;
|
||||
return 204;
|
||||
}
|
||||
|
||||
include /etc/nginx/nginx_dev_common.conf;
|
||||
|
||||
}
|
||||
|
||||
@@ -270,6 +270,26 @@
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Gitea's history views and archives, behind the admin gate. A crawler
|
||||
# swarm (129k requests from 103k IPs over 2026-10-18/19, so per-IP rate
|
||||
# limits are useless) walks every file at every commit, and those pages
|
||||
# are the expensive ones: diffs, blame, tarballs nginx spools to disk.
|
||||
# 89% of its requests were these shapes; people browsing the code use
|
||||
# the branch views (src/branch/..., commits/branch/...), which stay
|
||||
# public, so the CV's repo links still work. Gitea's own
|
||||
# REQUIRE_SIGNIN_VIEW=expensive would also block src/branch, hence
|
||||
# doing it here. A regex location, so it wins over /gitea/ above.
|
||||
location ~ ^/gitea/[^/]+/[^/]+/((src|raw|blame|commits|media)/commit/|commit/|archive/|compare/) {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
rewrite ^/gitea/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_gitea;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /notes {
|
||||
return 301 /notes/;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ http {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
# The container healthcheck's target; see nginx.conf.template.
|
||||
location = /nginx-health {
|
||||
access_log off;
|
||||
return 204;
|
||||
}
|
||||
|
||||
# All other requests should return 404
|
||||
location / {
|
||||
return 404;
|
||||
|
||||
Reference in New Issue
Block a user