Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am hosting two separate sites with two separate domain names on the same server. Without using some kind of NAT forwarding, how can I set up my apache server so that, depending on which domain is used, the index.html file from a different directory is referenced?

share|improve this question

migrated from stackoverflow.com Jul 28 '10 at 1:47

This question came from our site for professional and enthusiast programmers.

    
Beware ISP's that will be blocking you from serving a website from your home. –  Mitch Dempsey Jul 28 '10 at 0:00
    
Also beware dynamic IP addresses. See dyndns.com for one solution to the problem of changing home IP addresses. –  dgw Jul 28 '10 at 0:06

3 Answers 3

This question will probably be migrated to Server Fault shortly, but the basic answer is that you need to set up a Virtual Host for each of the domain names. This page has a thorough description but a basic example would be:

<VirtualHost *>
   DocumentRoot /path/to/site1
   ServerName site1.com
</VirtualHost>

<VirtualHost *>
   DocumentRoot /path/to/site2
   ServerName domain2.com
</VirtualHost>
share|improve this answer

Check out Apache's support for virtual named hosts, as described in the Apache 2.2 documentation. If both domains point to your home server's IP address in the DNS, you should be able to be up and running with a few changes to Apache's configuration file.

share|improve this answer

you will need a static ip address (or service that forwards to your ip address - pain in the back side as far as I'm concerned)...

but once you have that then you will need to configure virtual hosts...

If you have apache 2.2 you should have a 'extra' folder under 'conf' in your apache directory.

In this you will find httpd-vhost.conf which gives you the basic idea.

Finally in your main apache config file you will need to uncomment the line that includes teh vhost config...

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

and the line that loads the vhost module

#LoadModule vhost_alias_module modules/mod_vhost_alias.so
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.