Skip to content

Commit 2f6a70c

Browse files
committed
feat: add nginx reverse proxy for Plausible and security filtering
- Add nginx configuration with Plausible proxy routes and security filters - Configure Puma to bind to Unix socket with restricted permissions - Update Procfile to use bin/start-nginx wrapper - Update Plausible snippet to use proxied endpoints Security features: - Block malicious user agents (Nikto, sqlmap, etc.) with HTTP 444 - Block common attack paths (WP admin, .env, .git, etc.) - Add security headers: X-Frame-Options, X-Content-Type-Options, X-XSS-Protection, Referrer-Policy - Set proxy timeouts and request size limits Proxy caching: - Cache Plausible script in /dev/shm (Heroku tmpfs) for 5 minutes - X-Cache header for debugging cache hits/misses - 1m max cache size (single ~30KB JS file)
1 parent ae07616 commit 2f6a70c

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)