6

I am having trouble figuring out how to have multiple servers (that do different things) on one IP address. I would like the subdomains to point to different applications. Let me give an example of what I am trying to do. I choose a couple services just for this example. I am also using a couple of raspberry pi's that I have laying around for this project.

Say I have a web server that runs my website at "mydomain.com". But I also would like to run a Minecraft server of the same IP address but on a different server at "mc.mydomain.com". Then I would like to run an ownCloud server on a different server at "cloud.mydomain.com"

For this project I am using raspberry pi's and my domain is registered with Namecheap.

1
9

I assume this is a small office/home setup.

There is no way to assign the same IP to multiple devices. Therefore, you'll either have to host everything on the same device or use a mechanism that helps you to distribute the packets to the corresponding servers. I think what you need to look into here are ports, NAT and reverse proxies.

If you only have one single IP address available, you will have to either

  • Configure the public IP to a single device and distribute the requests within your local network
  • Host all services on the same hardware (e.g. your raspberry).

An example for port forwarding:

  • You configure cloud.mydomain.com to point at your IP. Here, you will run a web server on port 443 (https).
  • You configure mc.mydomain.com to point at your IP. Here, you will run your Minecraft server on a port of your choice, e.g. 25565.
  • You configure your firewall/router to forward everything that it receives on its public IP.
    • ...on port 443 to the raspberry that is hosting the ownCloud instance.
    • ...on port 25565 to the raspberry that is hosting the Minecraft server.
  • These can be different devices on your local network. You just set up the port forwarding or NAT rules.

An example using a proxy:

  • You want to run multiple web servers having only a single IP. You do not want to use different ports for different websites.
  • You configure your subdomains to point at your single IP.
  • You set up a port forwarding/NAT rule to forward any incoming traffic on port 443 to one of your raspberries.
  • You set up web servers on two other raspberries that shall each handle traffic for one of the subdomains.
  • On the first raspberry, you set up a reverse proxy, e.g. using Nginx. You set up different configurations for your subdomains: one for sub1.mydomain.com, one for sub2.mydomain.com, with proxy_pass directives pointing to other web servers within your local network.
  • Your Nginx-proxy now handles any incoming traffic, distributing it to the correct web server on the basis of the subdomain that the user is requesting.

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.