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 protected]
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 [email protected]
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!
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!