Apache – How to Point Sub-Domains to Different Local IPs

apache-2.2reverse-proxysubdomainubuntu-12.04

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>

Best Answer

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.

Related Topic