Skip to content

Commit 613c947

Browse files
committed
feat: add nginx reverse proxy for Plausible and security filtering
- Add nginx config with Plausible proxy routes (/js/script.js, /api/event) - Block malicious user agents and common attack paths with HTTP 444 - Add security headers (X-Frame-Options, X-Content-Type-Options, etc.) - Configure proxy caching in /dev/shm for 5 minutes - Configure Puma Unix socket binding for Heroku
1 parent ae07616 commit 613c947

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
@@ -9,6 +9,9 @@ http {
99
charset utf-8;
1010
server_tokens off;
1111

12+
# Proxy cache using /dev/shm (tmpfs, survives dyno restarts)
13+
proxy_cache_path /dev/shm/jscache levels=1:2 keys_zone=jscache:1m inactive=30d use_temp_path=off max_size=1m;
14+
1215
# Security headers (set at http level to apply to all responses)
1316
add_header X-Frame-Options "SAMEORIGIN" always;
1417
add_header X-Content-Type-Options "nosniff" always;
@@ -53,12 +56,18 @@ http {
5356
return 444;
5457
}
5558

56-
# Plausible: Proxy script.js
59+
# Plausible: Proxy script.js (with caching)
5760
location = /js/script.js {
5861
proxy_pass $plausible_script_url;
5962
proxy_set_header Host plausible.io;
6063
proxy_pass_header Cache-Control;
6164
proxy_buffering on;
65+
66+
# Cache for 5 minutes
67+
proxy_cache jscache;
68+
proxy_cache_valid 200 5m;
69+
proxy_cache_use_stale updating error timeout invalid_header http_500;
70+
add_header X-Cache $upstream_cache_status;
6271
}
6372

6473
# Plausible: Proxy event API

0 commit comments

Comments
 (0)