From 5e4c9c533e1e251d70bf6c68f8615a72317155a9 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Wed, 7 Jan 2026 21:12:30 +0100 Subject: [PATCH] Add a purge endpoint and add more header controls --- nginx.conf | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/nginx.conf b/nginx.conf index da30366..d68e103 100644 --- a/nginx.conf +++ b/nginx.conf @@ -11,11 +11,10 @@ http { proxy_cache_path /etc/nginx/data/cache levels=1:2 keys_zone=api_cache:10m max_size=100g inactive=365d; - error_log /dev/stdout debug; + error_log /dev/stdout warn; access_log /dev/stdout; - # Use Docker's internal DNS - resolver 127.0.0.11 valid=10s; + resolver 127.0.0.11 valid=60s; server { listen 3000; @@ -31,8 +30,26 @@ http { proxy_ssl_server_name on; proxy_cache api_cache; - proxy_cache_valid 200 365d; + + # Cache 2xx by default, or status codes from X-Status header + proxy_cache_valid 200 201 202 203 204 206 365d; + + # If X-Status header is present, cache those status codes instead + set $cache_status $http_x_status; + if ($cache_status != "") { + proxy_cache_valid $cache_status 365d; + } + + # Bypass cache if X-NoCache header is present + proxy_cache_bypass $http_x_nocache; + proxy_no_cache $http_x_nocache; + add_header X-Cache-Status $upstream_cache_status always; } + + # Cache purge endpoint + location ~ /purge(/.*) { + proxy_cache_purge api_cache $1; + } } } \ No newline at end of file