0

I have 3 app servers which are handled by nginx server.

upstream he {
    server h1.abc.example.com;
    server h2.abc.example.com;
}

How could I redirect requests request based on the some header value.Eg

  • abc-h1.abc.example.com should go to server h1.abc.example.com
  • def-h1.abc.example.com should go to server h2.abc.example.com

where -h1.abc.example.com is going be same for all requests

1
  • While technically it is a header value (Host header), these are destination domain names, which can be implemented easier than a generic header matching. Jul 7 '18 at 8:04
2

The most efficient way to do this would be with the server_name directive in multiple server blocks. Example:

server {
    server_name abc-h1.example.com;
    proxy_pass http://h1.example.com$request_uri;
}

server {
    server_name def-h1.example.com;
    proxy_pass http://h2.example.com$request_uri;
}

Obviously if you're not using NGINX as an HTTP proxy then replace proxy_pass with whatever directive is appropriate: fastcgi_pass, uwsgi_pass etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.