0

I host three websites on the same physical server, and of course by the Host header I know which website the user requests. For the sake of the example these are the domains:

  • blog.website1.example
  • shop.com
  • users.website2.example

There are around 4-5 companies which should use these websites, and I know their IP addresses. One of the companies requested that for their users, I add Javascript tracking (like google analytics). So I was wondering, how could I (based on the company IP addresses) analyze only their clients?

I wouldn't want to add it to one page / all companies. I want to append the script tag to all requested pages, requested by clients with specific IP address and I don't want to touch any of the website's code, and I also don't want all the clients receiving it (I dont want to do clientside filtering).

I really just want the script appended to specific IP's pages. Is it possible on both apache/nginx?

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
  • It's no trivial request. I don't know a module in Apache or nginx that touches the response body. As far as I know the websites will have to include a request for the javascript in all their pages, and then you can filter those requests, send something harmless to those domains that don't need tracking. If the solution isn't limited to Apache and Nginx, you could write your own reverse proxy in PHP, and let that one insert the request in the response body. Been there, done that. – Gerard H. Pille Jun 26 '18 at 12:20
  • @GerardH.Pille You can use `mod_ext_filter` in Apache to pass the response body to an external program. See http://httpd.apache.org/docs/2.4/mod/mod_ext_filter.html : *Pass the response body through an external program before delivery to the client* – Patrick Mevzek Jun 27 '18 at 02:02
  • The "not suitable for production use" doesn't worry you? – Gerard H. Pille Jun 27 '18 at 03:43
  • @GerardH.Pille That does not forbid trying... And the OP did not say how much business critical this is. Are lives in danger? Does a multimillion company depends on this? etc. In short, far too broad to see if it is appropriate or not, it is just an idea to explore. And since you said you do not know a module in Apache that touches the response body this shows you at least they exist... – Patrick Mevzek Jul 03 '18 at 03:44
  • @PatrickMevzek Why didn't you post it as an answer? – Gerard H. Pille Jul 05 '18 at 12:23

0 Answers0