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 had configured main host (doc root /var/www/html) and virtual host (doc root /var/www/html/vhosts ), but when I access main host(server2.example.com) it always gets forwarded to virtual host (Main host goes away). Below, I provided httpd.conf, please help me.

ServerAdmin root@localhost
ServerName server2.example.com:80
UseCanonicalName Off
DocumentRoot "/var/www/html"
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /var/www/html/web/test1.example.com
    ServerName test1.example.com
    ServerAdmin root@test1.example.com
    ErrorLog logs/test1.example.com-error_log
    CUstomLog logs/test1.example.com-access_log common
<Directory "/var/www/html/web/test1.example.com">
    order deny,allow
    deny from all
    allow from 192.168.122.1 
</Directory>
</VirtualHost>

Thanks in advance.

share|improve this question

1 Answer 1

Apache serves the first vhost that matches the Host: header or the first vhost defined (if no vhosts match the Host: header) so, when using name based virtual hosting, make both hosts virtualhosts and put the one you want to be the default host first.

This should serve server2.example.com for anything that's not test1.example.com.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin root@localhost
    ServerName server2.example.com:80
    UseCanonicalName Off
    DocumentRoot "/var/www/html"
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</virtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/web/test1.example.com
    ServerName test1.example.com
    ServerAdmin root@test1.example.com
    ErrorLog logs/test1.example.com-error_log
    CUstomLog logs/test1.example.com-access_log common
    <Directory "/var/www/html/web/test1.example.com">
        order deny,allow
        deny from all
        allow from 192.168.122.1 
    </Directory>
</VirtualHost>
share|improve this answer

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.