1+ daemon off;
2+ worker_processes auto;
3+
4+ events {
5+ worker_connections 1024;
6+ }
7+
8+ http {
9+ charset utf-8;
10+ server_tokens off;
11+
12+ # DNS resolver for proxy_pass
13+ resolver 9.9.9.9 valid=30s;
14+
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+
18+ # Logs to stdout/stderr for Heroku
19+ access_log /dev/stdout;
20+ error_log /dev/stderr;
21+
22+ # Proxy settings
23+ proxy_http_version 1.1;
24+ proxy_buffering on;
25+
26+ upstream app_server {
27+ server unix:/tmp/nginx.socket fail_timeout=0;
28+ }
29+
30+ server {
31+ listen <%= ENV["PORT"] %> ;
32+ server_name _;
33+ keepalive_timeout 5;
34+
35+ # Plausible endpoints (set inside server context)
36+ set $plausible_script_url https://plausible.io/js/pa-PFruVsE_br97UUCRXE_6f.js;
37+ set $plausible_event_url https://plausible.io/api/event;
38+
39+ # Plausible: Proxy script.js (cached)
40+ location = /js/script.js {
41+ proxy_cache plausible_cache;
42+ proxy_cache_valid 200 5m;
43+ proxy_cache_key "$host$uri";
44+ proxy_pass $plausible_script_url;
45+ proxy_set_header Host plausible.io;
46+ proxy_buffering on;
47+
48+ # Cache response headers
49+ add_header X-Cache $upstream_cache_status;
50+ }
51+
52+ # Plausible: Proxy event API
53+ location = /api/event {
54+ proxy_pass $plausible_event_url;
55+ proxy_set_header Host plausible.io;
56+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
58+ proxy_set_header X-Forwarded-Host $host;
59+ proxy_buffering on;
60+ }
61+
62+ # Rails: All other requests
63+ location / {
64+ proxy_pass http://app_server;
65+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
66+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
67+ proxy_set_header Host $http_host;
68+ proxy_redirect off;
69+ }
70+ }
71+ }
0 commit comments