So I have a main domaing pointing to my server (xx.xx.xx.xx).
I tried to create a subdomain with the following virtualhost file.
<VirtualHost myip:80>
ServerName sub.mydomain
</VirtualHost>
<VirtualHost myip:80>
ServerName mydomain.com
</VirtualHost>
- I didn't put all the other codes here.
I can't even ping sub.mydomain.com. My domain.com works just fine.
Am I doing something wrong here?
You need a valid DNS record for your subdomain too. You can accomplish this by either setting up an individual DNS entry for each new subdomain, or just creating a wildcard entry for *.domain.com that is a CNAME to domain.com. With the whildcard method, you can put whatever.domain.com in your apache config, and they will all just work without any other configuration. But every namebasedvirtualhost has to have a valid DNS entry.