4

I have a domain name mydomain.com which points to a static IP address. I have configured in my modem so that all request to port 80 of this static IP will come to my local computer 192.168.1.100 (web server).

Now I want to have 2 sub-domain point to 2 another local IP:
sub1.mydomain.com ---> 192.168.1.101 (host another web server)
sub2.mydomain.com ---> 192.168.1.102 (host redmine server)

Is this possible? If yes, please show me how?

I use Ubuntu Server 12.

4 Answers 4

3

Answer thanks to JoshP in Server Fault:

I just recently did this. See my question. It was kind of a long back and forth, but I did get it set up in the end.

  • Set up DNS. The A record will point to your public IP. So, yourdomain.com points to your.pub.ip.add. Add CNAME records for the subdomains. So, sub1.yourdomain.com points to @, and sub2.yourdomain.com points to @, etc. Although the subdomains are all pointing to the same address, the browser will confer to the webserver which subdomain you are trying to reach.

  • Set up Apache. You'll want to set up Virtual Hosts for each subdomain (and maybe for primary domain as well). You can define the Virtual Hosts in different places... mine is defined in /etc/apache2/sites-available, and includes the <Location> directive, which is where you'll set up your reverse proxy.

This answer was given to OP in ServerFault.

2
  • 1
    It's not a great answer though, without an example of e.g. the Virtual Hosts config..
    – geotheory
    Jun 3, 2016 at 13:58
  • @geotheory it doesn't really matter. It explains what is to be done and there are excellent guides elsewhere. As its now, if Apache (or whatever your webserver is) changes something this answer will be still canonical as it doesn't depends on the specific implementations of any version of the webserver.
    – Braiam
    Jun 3, 2016 at 15:29
0

The easiest way would be to modify your hosts file, which is in /etc/.

It would look like this:

# This is an example of the hosts file
127.0.0.1  localhost loopback
192.168.1.100 webserver
192.168.1.101 sub1
192.168.1.102 sub2
1
  • Hi badgerhill, I have changed my host file but it not works. When I ping mydomain.com, it show my static IP address, but ping the sub1.mydomain.com error show: "Ping request could not find host sub1.mydomain.com. Please check the name and try again". Please help!
    – thang nhoc
    Aug 8, 2012 at 3:40
0

Clients on your lan will need to have thier hosts file updated too unless you install and configure a DNS server too and have your clients use it. dnsmasq is easy and has lots of helpful comments in the config file. BIND is another but its config file uses a bizarre nonsensical syntax that nobody really understands. Unbound is another one with a strong emphasis on security.

0

If I understand correctly, you only have 1 public IP address (on inherently only 1 tcp port 80 on that), but you want to run 3 webservers of which only 1 is direcly public accessible (through a port forward).

You have 2 things to configure:

  1. DNS level: make sure www. sub1. sub2. all point to the same address as mydomain.com. This can be done in the configuration panel of your DNS registrar (look for a "Wildcard" option if available). This should allow you to ping sub1.mydomain.com and all other subdomains.
  2. As all requests arrive on the server 192.168.1.100, you'll need to configure this webserver to forward requests for the subdomains to other (internal) servers.

The other servers can be accessed if you use the main webserver (.100) as a reverse proxy for the subdomains sub1. and sub2.

I think this might be a good sample: sample httpd.conf with explanation

Note: in the ProxyPass and ProxyReverse lines you'll have to use an internal hostname or IP address, not the sub1.mydomain.com because that will have you end up with a loop!

If it doesn't work with that website, here are the google search terms: vhost reverse proxy

Good luck!

1
  • Thanks for your answer. Sorry but I don't have enough reputation to vote you up. Thanks again bro
    – thang nhoc
    Aug 14, 2012 at 2:34

You must log in to answer this question.

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