Home » Informational, Linux, Networking, Resources, Server, Ubuntu

Hosting 2 Domains with 1 Server

22 May 2009 4 Comments

This post will describe how to configure your Ubuntu Server 8.04 box for hosting multiple domains using Name based virtual hosting. You will need to have a true static ip with an Apache2 server configuration. There are 4 main editing components to this configuration (1) creating VirtualHost files for each domain, (2) editing your /etc/hosts, (3) adding a line of code to your /etc/apache2/apache2.conf file, and (4) enabling all of the changes. Let’s get started.

Configuring files in your /etc/apache2/sites-available file

I assume that you have 2 domain names that you have purchased and have already pointed your CNAME record to a static ip (your I hope). First, open up terminal and create a new file in your /etc/apache2/sites-available/domain1.conf. Title the file whatever you like, I named my file rbucky.com and it works well.

sudo vi /etc/apache2/sites-available/rbucky.com

The contents of that file are as follows:
<VirtualHost *:80> ServerName rbucky.com DocumentRoot /your/document/root/ </VirtualHost>

Do the same thing for your other domain. In other words, you will have a file for each domain in your /etc/apache2/sites-available/ folder for each domain. There is no need to alter your /etc/apache2/sites-available/default file. Just leave it alone.

Configuring your /etc/hosts file

I am not operating a DNS server, so my /etc/hosts file looks like this:

127.0.0.1    localhost 127.0.1.1    buckycomputing 192.168.1.105     buckycomputing microbucky.com rbucky.com

The 192.168.1.105 address is the internal ip of your server. You can locate that ip address by typing in ifconfig in terminal

Editing your /etc/apache2/apache2.conf file

This part is relatively simple. Using terminal or your favorite GUI editor, open up your /etc/apache2/apache2.conf file for editing and add the following line to the bottom of the file:

ServerName 192.168.1.105

Again, this is an example of the internal ip address. Make sure that you use your address.

Enabling the changes

You are almost home free. Using terminal, type in:

sudo a2ensite

Choose the two sites that you created. You will have to type in sudo a2ensite twice as you have 2 files. Next, restart Apache2 with:

sudo /etc/init.d/apache2 restart

Also, make sure that you have enable the apache2 vhost_alias module. Enable the module by typing
sudo a2enmod vhost_alias

Next, restart apache using the above command.

That should do it. If you have questions, comment on the article and I’ll do my best to get you up and running.

~Mark

4 Comments »

  • admin said:

    Added a third domain to this configuration. Still works great!

  • Jordan said:

    Hey there, i was following your guide, i have 3 domains and 1 IP address.

    I configured all the virtual hosts, but when i type in the domain names into my browser (e.g. domain1, domain2, domain3) i only get the HTML files loaded from domain1. I have specified different documentroots in the virtualhost configuration. I also get this message when restarting apache:

    *Restarting web server apache2
    [Sun Jun 28 11:18:28 2009] [error] (EAI 2) Name or service not known: Could not resolve host name *.80 — ignoring!
    [Sun Jun 28 11:18:28 2009] [error] (EAI 2) Name or service not known: Could not resolve host name *.80 — ignoring!
    [Sun Jun 28 11:18:38 2009] [error] (EAI 2) Name or service not known: Could not resolve host name *.80 — ignoring!
    [Sun Jun 28 11:18:38 2009] [error] (EAI 2) Name or service not known: Could not resolve host name *.80 — ignoring!

    any ideas?

    P.S- im the same guy from here:
    http://ubuntuforums.org/showthread.php?t=1198598

    i will post this there also.

    Thanks again!

  • admin said:

    Hello Jordan – Happy to help. UbuntuForums is down right now, so I cannot see the status of your post. There are a couple of potential areas that we can check. Check to ensure that you enabled each of your sites in terminal using the a2ensite and then restart apache2 service. Also, make sure that you append your /etc/hosts to include the domain2.com domain3.com. Do you have a static ip?

    Also, take a look at the apache page on Virtual Hosts here > http://httpd.apache.org/docs/2.2/vhosts/name-based.html

    If you are still having problems, let me know.

  • Rachel Shaw said:

    Great Resource! I am adding your blog to my favorites, given my interest in finding domain names. One of the sites that can help find great name suggestions is http://www.squadhelp.com. Most individuals receive 200+ domain name suggestions in 2 days for just $50. It is an online community of people who submit ideas – and the best idea wins the award amount. It sure beats the time and energy I would have spent myself to come up with names. You might want to check them out. Just thought your readers might find it interesting!

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.