server { listen 80; server_name your.domain.com; location = /analytics.js { # you have to compile nginx with http://nginx.org/en/docs/http/ngx_http_sub_module.html (this is not default) # and http://nginx.org/en/docs/http/ngx_http_proxy_module.html (it's a default module) proxy_set_header Accept-Encoding ""; sub_filter 'www.google-analytics.com' 'your.domain.com'; sub_filter_types *; sub_filter_once off; proxy_pass https://www.google-analytics.com/analytics.js; break; } location / { proxy_pass http://www.google-analytics.com/; } }