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 have a VPS that I've installed a Apache Web Server on. What I want to do is forward my own website domains to that server and host those websites' files inside my Apache Web Server. As far as I understand a DNS server is required to manage which domain is hosted where (IP-wise). But what I want to do is host my websites under the same IP address, the one that my web server has. How can I separate those websites' files inside my web server so I don't have to use http://host/foo for www.foo.com and http://host/bar for www.bar.com?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The technology that you are looking for is name based virtual hosting. Typically you would have DNS configured to point the domains to the IP of your server. Apache then uses the information in the Host: header to serve the information from the correct vhost.

Listen 80
NameVirtualHost *:80 

<VirtualHost *:80>

    ServerName foo.com
    Serveralias www.foo.com
    DocumentRoot /path/to/foo.com/root
    .
    .
    .
</VirtualHost>
<VirtualHost *:80>

    ServerName bar.com
    Serveralias www.bar.com
    DocumentRoot /path/to/bar.com/root
    .
    .
    .
</VirtualHost>
share|improve this answer
    
Thanks for explaining the logic and also giving an example, appreciated. –  Caner Öncü Sep 2 '12 at 11:46
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.