Hosting multiple distinct folders for distinct domains

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?


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.example.com
    Serveralias www.foo.example.com
    DocumentRoot /path/to/foo.example.com/root
    .
    .
    .
</VirtualHost>
<VirtualHost *:80>

    ServerName bar.example.com
    Serveralias www.bar.example.com
    DocumentRoot /path/to/bar.example.com/root
    .
    .
    .
</VirtualHost>