I have a question.
If I make an A record pointing to an Apache2 server, and make some virtualhosts with subdomains. Can I then access the subdomain without making another record?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You seem to be confusing DNS A records and Apache VirtualHosts. They operate on entirely different levels and aren't really interchangeable.
For Apache, when you designate a
<VirtualHost> stanza, you tell apache what to do when it receives requests for any of the
ServerNames in that stanza. However, until and unless those names point to your server in DNS, no one from the outside world will ever ask your server for them, so you need both.
(Yes, I know I'm skipping wildcards here, I'm trying to keep it straightforward for someone who's clearly new at DNS and webhosting)
Let's give an example: Say, you have an A record pointing
www.foo.com to your server at
220.127.116.11 . And you have the following
<VirtualHost *:80> ServerName www.foo.com DocumentRoot /var/www/html -- etcetera --- </VirtualHost>
This tells your apache server that any contacts on port 80 asking for www.foo.com should be handled according to the instructions in that stanza.
Now suppose you add a subdomain:
<VirtualHost *:80> ServerName sub.foo.com ServerAlias sub2.foo.com DocumentRoot /var/www/subdomain/html --- etc --- </VirtualHost>
You've now told your apache server how to respond to requests for
sub2.foo.com. However, until and unless you add an A record pointing
18.104.22.168 no one will know to ask your server for that domain.