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

I've been given a new domain www.mywebsite.com and I want to point it to a specific directory on my server: var/www/specific/path

What are the steps for doing it ? Could you suggest me a tutorial ?

I need to repeat the same operations for several domains.



NameVirtualHost a.b.c.d //I've hidden my real ip

<VirtualHost www.website.com:80>
    DocumentRoot /var/www/sites/website
    ServerName www.website.com
    CustomLog /var/log/apache2/website.com.access combined
share|improve this question

1 Answer 1

up vote 4 down vote accepted

I'm assuming you want to host multiple sites on a single IP address and that you're using apache. If so, then essentially, the following lines of code in my httpd.conf do the job for me:

NameVirtualHost a.b.c.d:80

<VirtualHost site1.company.com:80>
    DocumentRoot /path/to/site1/documentroot
    ServerName site1.company.com
    CustomLog /usr/local/apache/logs/site1.company.com.access combined

<VirtualHost site2.company.com:80>
    DocumentRoot /path/to/site2/documentroot
    ServerName www.brossi.net
    CustomLog /usr/local/apache/logs/site2.company.com.access combined

Where a.b.c.d is your server's IP address. Repeat VirtualHost declarations as you need them. The CustomLog declaration isn't vital, but it helps me to keep my sites' logs separately from one another.

You can find more documentation on apache at http://httpd.apache.org/docs/; click on the version of your apache server, then enter (eg) NameVirtualHost in the search box (though the doco for that can also be found directly at http://httpd.apache.org/docs/current/mod/core.html#namevirtualhost - it's not a feature that changes much between versions).

share|improve this answer
Sorry, I should have added that the apache project has a very nice piece of doco on all of this at httpd.apache.org/docs/current/vhosts –  MadHatter Sep 30 '10 at 10:09
@MadHatter Sorry for the delay, they finally transfer the domain, so I can only test now. Shortly, I cannot make it work, the domain doesn't lead to my website. I've updated the question with my current configuration. What am I missing ? –  Patrick Oct 7 '10 at 14:59
Also, this is what I get when I do add the NameVirtualHost line: [Thu Oct 07 16:51:46 2010] [warn] NameVirtualHost a.b.c.d:80 has no VirtualHosts –  Patrick Oct 7 '10 at 15:01
Could you confirm that, both on the machine in question, and on another random machine, when you nslookup www.website.com, you get a.b.c.d ? –  MadHatter Oct 7 '10 at 15:39
@MadHatter I actually get another ip. Wow. But I don't get why, I bought a VPS slice and they assigned me a specific ip. Then I transferred the domain, and they just assigned it to another ip ?! –  Patrick Oct 8 '10 at 7:11

Your Answer


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.