original post date: July 18, 2016

2018/3/11 update

There are a lot of problems with this approach (lack of access to real IP, etc.) , and given the improved availability of Google Analytics services in China, it is no longer recommended. If reliability is sought, it is recommended to use domestic services or self-built statistical services.

You can find nginx.conf for reversing proxy Google Analytics on Google, but most of them are for the old version. And so do reCaptcha's. After solving some issues, here's my code.

Attention: 1. ngx_http_substitutions_filter_module module needed。 2. DO NOT ADD X-Frame-Options DENY WHILE CONFIGURING SSL (SOMEORIGIN would be fine for self using, not tested) 3. After reverse proxy reCaptcha, challenge will be difficult. (Using proxies will reduce credibility, and some code uses complex obfuscations that result in client-side identification code can't be modified)

References:

[1] https://ruby-china.org/topics/27400

[2] https://rocfang.gitbooks.io/dev-notes/content/guan_yu_proxy_pass_de_can_shu_lu_jing_wen_ti.html

[3] https://www.v2ex.com/t/234923