From 6dfcd12e9e863d90e59622a0535d6d6c3693fb75 Mon Sep 17 00:00:00 2001 From: Nikita Savchenko Date: Wed, 13 May 2020 22:11:46 +0300 Subject: [PATCH] Update readme with proxy in front of proxy manual --- readme.md | 15 ++++++++++++++- src/modules/proxy.js | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index c3c20e9..329f5d2 100644 --- a/readme.md +++ b/readme.md @@ -115,7 +115,20 @@ Proxied: www.google-analytics.com/collect?v=1&_v=j73&a=531530768&t=pageview&_s=1 Check the [test-static/index.html](test-static/index.html) file's code to see how to bind the proxied analytics to your front end. -## Configuration +### Proxy in Front of the Proxy + +Before the request hits this NodeJS app / container, you have to proxy/assign some useful headers to it (`host` and `x-real-ip` or `x-forwarded-for`). Below is the example of the minimal Nginx proxy configuration. + +``` +location /gtm-proxy/ { + proxy_set_header Host $host; + proxy_set_header x-real-ip $remote_addr; + proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; + proxy_pass http://app-address-running-in-your-infrastructure; +} +``` + +## Configuration You can configure which third-parties to proxy/replace and how to do it in the config file. Find the actual configuration in [config.js](config.js) file: diff --git a/src/modules/proxy.js b/src/modules/proxy.js index b1620ae..54f9ff8 100644 --- a/src/modules/proxy.js +++ b/src/modules/proxy.js @@ -85,7 +85,7 @@ export function createDefaultProxy (targetDomain, proxyOptionsOverride = {}) { ) { const parsedUrl = url.parse(unmasked); - const pverwrittenIp = req.headers["x-forwarded-for"] || req.headers["x-real-ip"]; + const pverwrittenIp = req.headers["x-forwarded-for"] || req.headers["x-real-ip"]; // TODO: || req.connection.remoteAddress; // in case no proxy is used (dedicated domain) const clientIp = pverwrittenIp ? pverwrittenIp.split(/,\s?/g)[0] : req.connection.remoteAddress.split(":").pop();