4

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?

6

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>
| improve this answer | |
  • Thanks for explaining the logic and also giving an example, appreciated. – Caner Öncü Sep 2 '12 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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