I am not much of an admin (nor of an native english speaker, for that matter) and I am struggling with a simple task: add a subdomain on Apache 2.4. Here are my conf files:
<VirtualHost *:80>
ServerName domain.io
ServerAlias domain.io
ServerAlias *.domain.io
DocumentRoot /var/www/html/david
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
</VirtualHost>
And the second:
<VirtualHost *:80>
ServerName sub.domain.io
ServerAlias sub.domain.io
ServerAlias *.sub.domain.io
DocumentRoot /var/www/html/ness_pro
<Directory /var/www/html/ness_pro>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
</VirtualHost>
[the problem] Every time I try to access sub.domain.io with a browser, I end up on the page related to domain.io. I followed the guidelines of apache 2.4 (i.e. edit in sites-available -> a2ensite -> systemctl restart).
[about my DNS conf] I redirected sub.domain.io to domain.io on my DNS provider (Gandi). It points to the right url. I naively thought that apache would analyze the request url to dispatch between the different VHosts but it seems that I've been naive. Is there some easy way to fix this (I always found apache url rewriting pretty obscure)?
[env] Debian 9 (raspbian) // Apache 2.4
[edit] Since everyone is asking. Here is my DNS record
@ 10800 IN SOA ns1.gandi.net. hostmaster.gandi.net. 1542647212 10800 3600 604800 10800
@ 10800 IN A 77.193.111.117
@ 10800 IN MX 10 spool.mail.gandi.net.
@ 10800 IN MX 50 fb.mail.gandi.net.
@ 10800 IN TXT "v=spf1 include:_mailcust.gandi.net ?all"
blog 10800 IN CNAME blogs.vip.gandi.net.
sub 10800 IN CNAME webredir.vip.gandi.net.
webmail 10800 IN CNAME webmail.gandi.net.
www 10800 IN CNAME webredir.vip.gandi.net.
*.domain.io
is matching before thesub.domain.io
. Why don't you try to set both virtual hosts in the same file, but put thesub.domain.io
above the*.domain.io
000-default
, you can use 000 forsub.domain.io
and 001 fordomain.io
, check it out