nginx改写模块subs_filter
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
cd nginx-1.13.7
make clean
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-openssl=../openssl-1.0.2n --with-openssl-opt=enable-tls1_3 --with-ld-opt=-ljemalloc --add-module=../nginx-rtmp-module-master --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.12rc1 --add-module=../echo-nginx-module --with-stream --with-stream_ssl_module --add-module=../nginx_cookie_flag_module-master --add-module=../headers-more-nginx-module --add-module=../ngx_http_substitutions_filter_module
make -j 16
make install
nginx中添加百度统计的subs_filter模块
只需要在相应站点的location下面添加这段代码就行了:
subs_filter </body> '<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?35599ddsdsdsdsdsdsd"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script></body>';
#替换成自己项目的百度统计代码。