Skip to content

Commit 891a726

Browse files
committed
feat: add proxy_cache in /dev/shm for Plausible script
- Cache size: 1m keysZone, 100m max - TTL: 5 minutes - Cache hit/miss tracked via X-Cache header
1 parent 1e6e771 commit 891a726

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

config/nginx.conf.erb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ http {
1212
# DNS resolver for proxy_pass
1313
resolver 9.9.9.9 valid=30s;
1414

15+
# Proxy cache in /dev/shm (tmpfs, persists across dyno restarts)
16+
proxy_cache_path /dev/shm/nginx_cache levels=1:2 keys_zone=plausible_cache:1m max_size=100m inactive=5m use_temp_path=off;
17+
1518
# Security headers
1619
add_header X-Frame-Options "SAMEORIGIN" always;
1720
add_header X-Content-Type-Options "nosniff" always;
@@ -39,11 +42,17 @@ http {
3942
set $plausible_script_url https://plausible.io/js/pa-PFruVsE_br97UUCRXE_6f.js;
4043
set $plausible_event_url https://plausible.io/api/event;
4144

42-
# Plausible: Proxy script.js
45+
# Plausible: Proxy script.js (cached)
4346
location = /js/script.js {
47+
proxy_cache plausible_cache;
48+
proxy_cache_valid 200 5m;
49+
proxy_cache_key "$host$uri";
4450
proxy_pass $plausible_script_url;
4551
proxy_set_header Host plausible.io;
4652
proxy_buffering on;
53+
54+
# Cache response headers
55+
add_header X-Cache $upstream_cache_status;
4756
}
4857

4958
# Plausible: Proxy event API

0 commit comments

Comments
 (0)