I have two virtual hosts on one IP, www.example.com and www.example2.com. The default, example.com, has a subdomain, docs.example.com that works fine, and it also has an SSL certificate, and it forces https on example.com.
When I try to set up a subdomain on the second domain, i.e. blog.example2.com (wordpress), it redirects back to the first domain, https://www.example.com. www.example2.com works fine though.
Is it possible to have subdomains for two sites on one IP? Or can you only have subdomains for the default? Is there any way to get subdomain on example2 to work?
Config files:
000-default.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
...
DocumentRoot /var/www/example.com/public_html
</VirtualHost>
example.com.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
...
DocumentRoot /var/www/example.com/public_html
</VirtualHost>
<IfModule mod_ssl.c>
... certificates set up etc.
</IfModule>
docs.example.com.conf
<VirtualHost *:80>
ServerName docs.example.com
...
DocumentRoot /var/www/docs.example.com/public_html
</VirtualHost>
example2.com.conf
<VirtualHost *:80>
ServerName www.example2.com
ServerAlias example2.com
...
DocumentRoot /var/www/example2.com/public_html
</VirtualHost>
blog.example2.com.conf
<VirtualHost *:80>
ServerName blog.example2.com <-- redirects back to https://www.example.com
...
DocumentRoot /var/www/blog.example2.com/public_html
</VirtualHost>