4

I was wondering if it is possible to direct http traffic to a specific back end server, based on an http request header value. The 'referer' http header value for exemple.

I have 2 server instances. One for UAT (tests) and one for pre-production use. I would like to have an Apache reverse proxy in front of these 2 server instances. And when an http request comes, based on the 'referer' http header (uat or pre-prod) value I would like my reverse proxy to direct the request to the correct back end server instance.

Is this possible?

Thanks

Dan
  • 41
  • 1
  • 1
  • 2
  • Can you give an example for the UAT and pre-prod requests and where they go to? It really depends on what part of the referrer you wish to use in order to determine the underlying server you want to proxy the request to The answer below from Dti has the beginnings of a solution, but will probably not work according to your description. – Unbeliever Oct 09 '16 at 09:56
  • Hello Unbeliever. The web app on UAT has a domaine name with "webapp-uat" . And in QA, it will have "webapp-qa". So when the AJAX HTTP requests are sent to my Apache reverse proxy, the HTTP requests will have one of these 2 domaine names in the referer header. Then I would like my mod_proxy config to proxy for the correct of the 2 backend servers (search-uat or search-qa), based on the domaine name of the referer. – Dan Oct 09 '16 at 19:26

2 Answers2

3

Yes, it is possible.

Make a rewrite rule based on a conditional check of the REFERER header.

RewriteCond documentation

%{HTTP:header}, where header can be any HTTP MIME-header name, can always be used to obtain the value of a header sent in the HTTP request. Example: %{HTTP:Proxy-Connection} is the value of the HTTP header ``Proxy-Connection:''.

RewriteCond %{HTTP:Referer} =="xyz.com/abcd"
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Dti
  • 66
  • 3
  • Thanks Dti. But if I use rewriteRule, I will see the name of the back end servers in rewritten urls, right? I was thinking reverse proxy, so that the url does not change but behind the scenes, mod_proxy redirects the http request to the uat or pre-prod server transparently for the user. – Dan Oct 09 '16 at 10:43
1

May need more information (i.e. more precise examples) to be more accurate, but here is something to work with.

RewriteCond %{HTTP:Referer} webapp-uat
RewriteRule (.*) http:/uat-backend/$1 [P,L]

RewriteCond %{HTTP:Referer} webapp-qa
RewriteRule (.*) http:/qa-backend/$1 [P,L]

I hope that gives you enough to get started.

Unbeliever
  • 2,336
  • 1
  • 10
  • 19