8

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.

monarch8
  • 81
  • 1
  • 1
  • 3
  • 5
    Possible duplicate of [How do I host multiple physical Web servers behind a single IP address?](http://superuser.com/questions/610882/how-do-i-host-multiple-physical-web-servers-behind-a-single-ip-address) – music2myear Mar 07 '17 at 22:31

3 Answers3

10

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.
Patrick R.
  • 1,311
  • 1
  • 11
  • 24
0

If your using an apache web server you can use a virtual hosts to do this for web applications. Virtual hosts enable you to host multiple websites from a single web server.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 15 '21 at 03:14
-1

This is possible with a reverse proxy.

https://mywebsite1.com --> YOUR PUBLIC IP ADDRESS --> http://192.168.1.X

https://mywebsite2.com --> YOUR PUBLIC IP ADDRESS --> http://192.168.1.Y

The reverse proxy listen on the port :80, detect the origin of the request and then send request to the target that you assign to this origin.

For the reverse proxy, I personally use "Nginx Proxy Manager" on a Raspberry Pi : https://nginxproxymanager.com

Fred
  • 1