-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add nginx reverse proxy for Plausible analytics #2595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mroderick
wants to merge
1
commit into
codebar:master
Choose a base branch
from
mroderick:feature/nginx-plausible-proxy-clean
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| release: bundle exec rake db:migrate | ||
| web: bundle exec puma -C config/puma.rb | ||
| web: bin/start-nginx bundle exec puma -C config/puma.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| daemon off; | ||
| worker_processes auto; | ||
|
|
||
| events { | ||
| worker_connections 1024; | ||
| } | ||
|
|
||
| http { | ||
| charset utf-8; | ||
| server_tokens off; | ||
|
|
||
| # DNS resolver for proxy_pass | ||
| resolver 9.9.9.9 valid=30s; | ||
|
|
||
| # Proxy cache in /dev/shm (tmpfs, persists across dyno restarts) | ||
| proxy_cache_path /dev/shm/nginx_cache levels=1:2 keys_zone=plausible_cache:1m max_size=100m inactive=5m use_temp_path=off; | ||
|
|
||
| # Security headers | ||
| add_header X-Frame-Options "SAMEORIGIN" always; | ||
| add_header X-Content-Type-Options "nosniff" always; | ||
| add_header X-XSS-Protection "1; mode=block" always; | ||
| add_header Referrer-Policy "strict-origin-when-cross-origin" always; | ||
|
|
||
| # Logs to stdout/stderr for Heroku | ||
| access_log /dev/stdout; | ||
| error_log /dev/stderr; | ||
|
|
||
| # Proxy settings | ||
| proxy_http_version 1.1; | ||
| proxy_buffering on; | ||
|
|
||
| upstream app_server { | ||
| server unix:/tmp/nginx.socket fail_timeout=0; | ||
| } | ||
|
|
||
| server { | ||
| listen <%= ENV["PORT"] %>; | ||
| server_name _; | ||
| keepalive_timeout 5; | ||
|
|
||
| # Plausible endpoints (set inside server context) | ||
| set $plausible_script_url https://plausible.io/js/pa-PFruVsE_br97UUCRXE_6f.js; | ||
| set $plausible_event_url https://plausible.io/api/event; | ||
|
|
||
| # Plausible: Proxy script.js (cached) | ||
| location = /js/script.js { | ||
| proxy_cache plausible_cache; | ||
| proxy_cache_valid 200 5m; | ||
| proxy_cache_key "$host$uri"; | ||
| proxy_pass $plausible_script_url; | ||
| proxy_set_header Host plausible.io; | ||
| proxy_buffering on; | ||
|
|
||
| # Cache response headers | ||
| add_header X-Cache $upstream_cache_status; | ||
| } | ||
|
|
||
| # Plausible: Proxy event API | ||
| location = /api/event { | ||
| proxy_pass $plausible_event_url; | ||
| proxy_set_header Host plausible.io; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; | ||
| proxy_set_header X-Forwarded-Host $host; | ||
| proxy_buffering on; | ||
| } | ||
|
|
||
| # Rails: All other requests | ||
| location / { | ||
| proxy_pass http://app_server; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; | ||
| proxy_set_header Host $http_host; | ||
| proxy_redirect off; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.