Adam Copley Adam Copley - 28 days ago 7
Apache Configuration Question

apache not handling subdomains properly virtual hosts windows

I have searched many a post and tried every different way of configuring this in httpd.conf.

I'm running Apache 2.4 on windows server 2012 with PHP 5.6 and MySQL. On an amazon EC2 instance. I have all the correct security settings, and I have also setup my dns properly in route S3 to point to my EC2, have A entries for my subdomains. The primary domain www.mydomain.com is working fine and pointing to the correct location htdocs. However my subdomains aren't being mapped to the folder I've defined as below:

NameVirtualHost ip.ip.ip.ip:80

<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DocumentRoot c:/Apache24/htdocs
DirectoryIndex index.php index.htm index.html
</VirtualHost>

<VirtualHost *:80>
DocumentRoot c:/Apache24/htdocs/sub1
ServerName sub1.mydomain.com
DirectoryIndex index.php index.htm index.html
ErrorLog logs/sub1-error.txt
CustomLog logs/sub1-access.txt common
</VirtualHost>

<VirtualHost *:80>
DocumentRoot c:/Apache24/htdocs/phpMyAdmin
ServerName phpmyadmin.mydomain.com
DirectoryIndex index.php index.htm index.html
ErrorLog logs/phpmyadmin-error.txt
CustomLog logs/phpmyadmin-access.txt common
</VirtualHost>


All help greatly appreciated.

I also have these entries in my HOSTS file

ip.ip.ip.ip mydomain.com
ip.ip.ip.ip *.mydomain.com
ip.ip.ip.ip sub1.mydomain.com
ip.ip.ip.ip phpmyadmin.mydomain.com


ip.ip.ip.ip is my server's public IP address.

Answer Source

Strangely enough I tried the solution from @Gillsoft AB. And when I tried to restart apache it failed to restart. Then I reverted back to where I was. Then changed each <VirtualHost *:80> to <VirtuHost ip.ip.ip.ip:80>, rebooted, This didn't work. Then I went back to how it originally was when I first posted, rebooted again. And now it works????