Is it possible to configure nginx (or apache) to use a different backend server based on the request domain?
For example:
For a request for srv1.pod1.mydomain.com should go to srv1.pod1.external
For a request for srv1.pod2.mydomain.com should go to srv1.pod2.external
...
For a request for srv1.podN.mydomain.com should go to srv1.podN.external
I was looking at the rewrite rule but it doesn't seem to rewrite the domain, just the path.
server {
listen 80 ([^.]+).(\w+).mydomain.com;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
proxy_pass $1.$2.external;
}
}
Your config seems a little broken. Server names does not apply to
listen
directive, also you have a mistakes in your regular expressions. Try this:When you specify your backend server with domain name, you need to specify the additional parameter
resolver
in your server config. You can use your local name server if you have one, or use something external like Google public DNS (8.8.8.8) or DNS provided for you by your ISP.