Search code examples
nginxdebianiptables

Reroute a specific domain to another server IP


I have a server that gets all requests from 3 different domain names. I would like to reroute two of the domain in another local IP.

Actually I have :

  • abc.com => my_server
  • subdomain.abc.com => my_server
  • subdomain2.abc.com => my_server

And I would like to get :

  • abc.com => my_server
  • subdomain.abc.com:* => my_server => 192.168.0.70:*
  • subdomain2.abc.com:* => my_server => 192.168.0.72:*

But I don't know how to do that, any idea, software/script name on debian ?

Thanks !


Solution

  • You can use proxy for what you expect and multiply configuration to manage all port needed. Following config will proxy all request for: subdomain.abc.com:80 => 192.168.0.70:80

    server {
        listen 80; 
        server_name subdomain.abc.com;
        location / {
            proxy_pass http://192.168.0.70:80;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
    

    Unfortunately according to the documentation port number can't be dynamic and should be hard coded on your configuration file.