Created
January 7, 2019 14:31
-
-
Save bblanchon/39b5dce9ea0b16fce1ea6a365d1f786a to your computer and use it in GitHub Desktop.
NGINX proxy for Google Analytics, allows you to bypass ad blockers
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
# /etc/nginx/sites-available/ga.example.com.conf | |
# | |
# Example of an host that uses the snippet | |
server { | |
listen 80; | |
server_name ga.example.com; | |
# verify that the query relates to my account | |
if ($arg_tid !~ "^$|^UA-XXXXXXXX-") { | |
return 403; | |
} | |
include snippets/google-analytics-proxy.conf; | |
} |
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
# /etc/nginx/snippets/google-analytics-proxy.conf | |
# | |
# A reusable configuration to proxy Google Analytics | |
proxy_buffering on; | |
proxy_cache TMP; | |
location = /analytics.js { | |
proxy_set_header Accept-Encoding ""; | |
sub_filter 'www.google-analytics.com' $server_name; | |
sub_filter_types *; | |
sub_filter_once off; | |
proxy_pass https://www.google-analytics.com/analytics.js; | |
break; | |
} | |
location / { | |
# Override IP address | |
set $args $args&uip=$remote_addr; | |
proxy_pass https://www.google-analytics.com; # CAUTION: no trailing slash | |
} |
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
# /etc/nginx/conf.d/tmp-cache.conf | |
# | |
# Configure a small cache named TMP | |
proxy_cache_path /tmp/nginx keys_zone=TMP:10m max_size=100m; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment