Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two domains and being hosted on two different machines on my local network and rather than using port forwarding I would rather have all traffic for each domain forwarded by the router to the right machine. Would I need to setup a DNS Server to accomplish this or are there other alternative to get this to work?

share|improve this question
Do you only have one public IP address? What router do you have? Most likely, you need what is called a reverse proxy. "Reverse proxies can be used whenever multiple web servers must be accessible via a single public IP address. The web servers listen on ... different machines and different local IP addresses altogether. The reverse proxy analyzes each incoming call and delivers it to the right server within the local area network." – David Schwartz Aug 2 '12 at 19:41
Yeah only one ip address. Is this something that is done at a router level or would I have to setup a machine for this. – dadougster Aug 2 '12 at 20:22
Some routers can do it. The simplest solution is probably to pick one of the two machines (the more powerful, busier, or more reliable one), port forward to it, and then configure that machine to act as a reverse proxy for misdirected requests. (The reason to pick the busier machine is so that fewer connections will need to be proxied.) – David Schwartz Aug 2 '12 at 20:30
up vote 1 down vote accepted

There are two approaches to this depending on what your ISP and router can support. However, you should note from the outset that your router cannot tell the difference between different sub-domains, it only routes on IP address and port not by name.

The least likely approach is that your ISP can provide more than one IP address and that your Router can also handle this (my old Draytek router could, my new Billion router cannot). In that case, you would set up a public DNS (not local) that pointed the two sub-domains at the different addresses and, in the router, made sure that you also routed those addresses accordingly. The router would then need to forward port 80 on each IP address to a single IP address (the hosting PC, I assume they are both on a single box?) but two different ports. This is by far the easiest and most robust approach. If you indicate that this is the desired approach, I can update the answer with more details on how to set up Apache and the PC correctly.

More likely is that you will only have a single external IP address available to you. Now things are a little more difficult since both sub-domains must be directed at a single external IP address and will be NAT'ed to a single internal address/port since the router cannot differentiate the traffic. In this instance, you will need to (as David has indicated) set up a reverse proxy. This can be done using either a dedicated proxy tool or via mod_proxy in Apache (other web servers such as NGINX can also do it). You also need to make sure that your two web apps actually work behind a reverse proxy, some do not.

A reverse proxy will take traffic for each sub-domain and transparently forward it to an internal address/port combination so that the two apps will run on separate ports on the host PC. For simple web apps, the configuration is straight-forwards but for complex apps, the configuration can be somewhat complex to get right.

In both cases, you need the help of an external DNS not an internal one.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .