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 very basic knowledge of how a web server works. I wish to learn how to set a third level domains test1.mysite.tld such that it points to a web server subdirectory /var/www/test1/. (www.mysite.tld should keep to point to main directory). I am on a machine with Debian. I defined a virtual host within apache2.conf

<VirtualHost *>
ServerName test1.mysite.tld
DocumentRoot /var/www/test1/
LogLevel debug
ErrorLog other_vhosts_access.log
</VirtualHost>

Still, when I try url test1.mysite.tld, /var/www/index.html is returned, instead of /var/www/test1/index.html.

Do I miss something? A rewrite rule? Do I need to do anything for the DNS? Thanks for your help

share|improve this question

1 Answer 1

You need to configure name based virtual hosting. The first thing to do is configure the DNS so that test1.mysite.tld resolves to the IP address of your server. How you do this depends upon how your DNS services are provided.

Basic Apache configuration would be something like

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>

    ServerName www.mysite.tld 
    Serveralias mysite.tld
    DocumentRoot /var/www/mysite.tld
    ...
</VirtualHost>

<VirtualHost *:80>
    ServerName test1.mysite.tld
    DocumentRoot /var/www/test1/
    LogLevel debug
    ErrorLog other_vhosts_access.log
</VirtualHost>
share|improve this answer
    
Thks. I am looking around and it seems that Debian has its own way to deal with apache and virtual hosts. Do I need to look at that? For the DNS, I am thinking that to have both www and * to point to the same IP is enough, am I wrong? –  mario Dec 2 '12 at 18:52
    
A basic tutorial helped a lot. I see what I want to see. So far so good. However, when I restart Apache I get a couple of error msgs. I'm trying to understand why, otherwise I will make a new question. Tkhs to all. –  mario Dec 2 '12 at 20:59

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.