6

My question is the same with How to point a subdomain to local server with dynamic IP. The difference is that I do have a static IP from my ISP, I think i do not need to use DynDNS right? so what can I use instead?

My goal is to point each subdomain to different web server like this:
mydomain.com --> 192.168.1.100 (main web server)
sub1.mydomain.com --> 192.168.1.101(web server 1)
sub2.mydomain.com --> 192.168.1.102(web server 2)

I have tried to use proxy module of Apache follow instruction here but not succeed. When i access to sub1.mydomain.com by browser, it always lead to mydomain.com.
Can I do this by this approach? if not please show me another way.

I use Ubuntu Server 12.04

[SOLVED]
Solution

  1. Set up DNS

The A record point to public IP:
1 @ public.ip
2 www public.ip

The CNAME record point to subdomain:
1 sub1 mydomain.com
2 sub2 mydomain.com

  1. Set up Apache.

Add sub1 and sub2 to /etc/apache2/sites-available

sub1:

<VirtualHost *:80>    
        ServerName sub1.mydomain.com    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://192.168.1.101/
                ProxyPassReverse http://192.168.1.101/
        </Location>    
</VirtualHost>

sub2:

<VirtualHost *:80>    
        ServerName sub2.mydomain.com    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://192.168.1.102/
                ProxyPassReverse http://192.168.1.102/
        </Location>    
</VirtualHost>
6
  • Your description of the problem consists of only two words, "not succeed". That's not really helpful. What exactly did you try? How far did you get? What went wrong? Aug 9, 2012 at 7:14
  • hi David, thanks for your reply. I edited my question.
    – thang nhoc
    Aug 9, 2012 at 10:14
  • @thang nhoc: Please edit your question, and add more detail (it seems you have only added more text). Specifically, start by answering the questions above, and include the relevant part of the configs. Aug 9, 2012 at 10:30
  • @Piskvor: sorry for the confusion. I want something like a "proxy server" so that when request come to sub1.mydomain.com it will be redirected to 192.168.1.101, so I try with proxy module of Apache. I do as the instruction from the link above but when i access to sub1.mydomain.com by browser, it always lead to mydomain.com. That is my problem
    – thang nhoc
    Aug 9, 2012 at 11:08
  • Post your apache configuration. It sounds like it's incorrect for sub1 and/or sub2. Aug 9, 2012 at 11:12

3 Answers 3

1

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.

3
  • I do as your instruction, It works perfectly for me. Thank you so much bro!
    – thang nhoc
    Aug 10, 2012 at 4:49
  • @thangnhoc wonderful!
    – JoshP
    Aug 10, 2012 at 4:52
  • 1
    This would be more helpful with an example
    – geotheory
    Jun 3, 2016 at 13:57
4

This isn't really a web server issue, it should be sorted out in your DNS. You control the DNS for mydomain.com, right? So add A records for the subdomains pointing to the relevant IP addresses, ensure those addresses are served by web servers that know they should be serving those domains, and all will work.

Having all subdomain requests go through the main webserver for mydomain.com, like some kind of weird load-balancer, is inefficient and unnecessary.

Edit: sorry, I had not appreciated that you were using 192.168.0.0/16 addresses to signify that your subdomain servers were on an internal network; I had thought that you were merely redacting the addresses as you had redacted the domain names.

So: are all the webservers on the internal network? Or only the subdomain ones? If the latter, what kind of VPN connection is there currently between the main web server and the internal servers?

2
  • Hi MadHatter, thanks for your reply. I add A records for subdomain pointing to the relevant IP addresses(local IP address 192.168.1.xxx) and it works but only when I'm in my local network, not outside - from the internet. If this is inefficient and unnecessary as you said, what should I do? I want to access 2 more web server from internet without buying more domain name.
    – thang nhoc
    Aug 9, 2012 at 10:51
  • 1
    @thangnhoc you are looking the wrong place. You don't have neither a DNS issue nor a web server issue. Your issue is the setup of your network. All your webservers needs external IP's for them to be reached from outside your network. Also make sure that the right ports are opened/forwareded in the firewall(s)
    – Frederik
    Aug 9, 2012 at 11:29
0

If I understand you correctly, here is your situation:

  • You have a single external IP address
  • You have multiple internal web servers (as in: different physical machines or VMs, not just different web roots on the same web server)

In such a case, you cannot rely on using a different IP for each domain because, well, you have only one. You cannot either simply tell Apache to use the "host" HTTP header to route to the right sub-domain because you have more than on setup of apache, all on different internal IPs.

In such case, I would use Squid in reverse proxy mode: Install it on a "simple" machine and the have it redirect requests to each web server, local or remote.

It is rather easy to setup: check out this page from the standard squid documentation as it describe exactly what you want to do: http://wiki.squid-cache.org/ConfigExamples/Reverse/MultipleWebservers

Please not that using a reverse proxy can cause some issues with application compatibility and that setting up SSL is delicate in such a scenario (but it can be done).

1
  • Thanks so much for your reply. This is exactly what I face up to. A good news in the morning, I'll try Squid and show you my result. Thanks again!
    – thang nhoc
    Aug 10, 2012 at 2:13

You must log in to answer this question.

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