-2

I am new to the world of server administration and am trying to learn from the ground up. I am running an Apache2 server on Google Compute Engine and am configuring my domain with Google Domains.

Lets say I have example.io and I want to make sub.example.io

Right now, example.io and sub.example.io both return the content in the directory I've created for sub.example.io.

I'm not sure if the fault is in sub.example.conf, example.conf or my DNS settings.

I've only found people asking about the exact opposite (sub.example.io returns example.io).

example.conf

<VirtualHost *:80>
ServerName example.io

DocumentRoot /var/www/html

<Directory /var/www/html>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sub.example.conf

NameVirtualHost *:80

<VirtualHost *:80>
ServerName sub.example.io

DocumentRoot /var/www/sub/public

<Directory /var/www/sub/public>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/sub-error.log

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/sub-access.log combined
</VirtualHost>

And finally my DNS configuration on domains.google.com

Registered hosts:
Host name: sub.example.com
IPV4 Address: servers ip


Custom resource records:
Name: @ Type: A Data: servers ip
Name: sub Type: A Data: servers ip
Name: www Type: CNAME Data: example.io
pinglock
  • 111
  • 1
  • 1
    Possible duplicate of [Apache configuration for main host and virtual host](http://serverfault.com/questions/489415/apache-configuration-for-main-host-and-virtual-host) – user9517 Mar 25 '17 at 08:35

1 Answers1

1

When Apache can't find the right vhost based on ServerName and ServerAlias, it returns the first vhost it can find. This is usually the first file in the vhosts folder alphabetically.

Your ServerName example.io does not match www.example.io if you were visiting with the www. prefix.

You can add ServerAlias www.example.io to also match the www subdomain.

jedifans
  • 206
  • 1
  • 4