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 have a website with Apache webserver, which hosts some subdomains too.

The problem I face is that once I activate any virtualhost, the main site keeps redirecting to the (yet only) virtualhost I have.

If I deactivate the virtualhost, everything works fine at the main site, but without my needed subdomain.

I'm using apache 2.2.19-1 under ArchLinux.

I have mydomain.com as the main site with the following httpd.conf:

ServerRoot "/etc/httpd"
Listen 80

#LoadModule section... a lot of LoadModule I omit

User http
Group http

ServerAdmin email@mydomain.com

ServerName mydomain.com:80

DocumentRoot "/srv/http"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "/srv/http">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

ErrorLog "/var/log/httpd/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "/var/log/httpd/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/srv/http/cgi-bin/"
</IfModule>

<Directory "/srv/http/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

# Some included conf files follow, I won't post them, just vhosts, but if needed ask me and I'll post them. As far as I know they aren't relevant
# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
Include conf/extra/httpd-autoindex.conf
# Language settings
Include conf/extra/httpd-languages.conf
# User home directories
Include conf/extra/httpd-userdir.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Various default settings
Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
  SSLRandomSeed startup builtin
  SSLRandomSeed connect builtin
</IfModule>

Here's my conf/extra/httpd-vhosts.conf:

NameVirtualHost *:80
Include conf/extra/vhosts/

And finally my conf/extra/vhosts/yetonlyvhost.conf

<VirtualHost *:80>
     ServerAdmin mail@mydomain.com
     ServerName subdomain.mydomain.com
     ServerAlias subdomain.mydomain.com
     DocumentRoot "/home/myuser/subdomaindir"
     DirectoryIndex indice.html
     ErrorLog "/var/log/httpd/vhost-error_log"
     CustomLog "/var/log/httpd/vhost-access_log" combined

    <Directory "/home/myuser/subdomaindir">
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

(subdomain index must be file named 'indice.html')

Any ideas of what am I doing wrong? I had some similar configuration before on other server I lost, but I'm pretty sure almost is ok in here, but I haven't found what's wrong now...

Thank you!

share|improve this question
2  
pretty sure once you add any virtual hosts, you need to convert your main host into a virtual host as well. –  Steve Kehlet Jun 3 '11 at 18:54
1  
you can see the hosts apache sees with apachectl -S –  DTest Jun 3 '11 at 18:56
    
Thank you! that was it: the main host must be a virtual one... doing so, is the info at the httpd.conf about the main host redundant? –  Javier Novoa C. Jun 3 '11 at 19:08
    
Yep it is redundant. Don't forget that if Apache is asked for a website that is not configured it uses the default one, which is the first one in the virtualhosts listing. –  Olivier Pons Jun 6 '11 at 21:20
    
By the way you could answer yourself to close this question =) –  Olivier Pons Jun 6 '11 at 21:20

1 Answer 1

The solution is pretty simple:

just have another virtual host for the main host too. When Apache is asked for a website that is not configured it uses the default one, which is the first one in the virtualhosts listings...

Thanks!

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.