Changing A record and CNAME records
Currently I'm using a LAMP
configuration for both my landing page page, for the web app, and for the APIs. Now I'd like to split these things across multiple Virtual Servers (VS). I'm unsure of the network settings and before messing up all my DNS configurations I'd like to understand if I'm about to crash my configuration.
The landing page is hosted at the second level domain
(e.g. myurl.com
), the web app is hosted at the lower level domain app.myurl.com
, and the api at api.myurl.com
. I also have a preview domain: preview.myurl.com
, used for testing.
Since everything is hosted on the same VS, I currently have also four different folders (landing
, api
, webapp
, preview
), that act as "virtual hosts" for each subdomain.
My DNS configuration looks like this:
myurl.com. A 300 123.123.123.123
www.myurl.com. CNAME 300 myurl.com.
api.myurl.com. CNAME 300 myurl.com.
app.myurl.com. CNAME 300 myurl.com.
preview.myurl.com. CNAME 300 myurl.com.
To start I'd like to change the data of each CNAME entry to the actual IP of the current VS. So that it would look like this:
myurl.com. A 300 123.123.123.123
www.myurl.com. CNAME 300 myurl.com.
api.myurl.com. CNAME 300 123.123.123.123
app.myurl.com. CNAME 300 123.123.123.123
preview.myurl.com. CNAME 300 123.123.123.123
Then the idea is to point each subdomain to the proper VS. Initially all lower level domains (except for www.
) will still be pointing to the current VS, while the second level domain for the landing page (A
record for myurl.com.
) will need to point to a new IP
for a new VS.
Questions:
- Will these changes affect the way in which the current Apache Server is distributing the traffic to each subfolder (i.e.
landing
,api
,webapp
,preview
)? If so, even if allIP
addresses remain the same? - To test things out, could I start by changing only the
data
value forpreview.myurl.com.
without risking of compromising the rest? - Once all lower level domains (e.g. api.myurl.com) point to the IP of the VM, can I point the
A
value ofmyurl.com.
to a different IP without compromising the other lower level domains (api
,app
,preview
)?
Solution 1:
As mentioned in the comments, you will need to use A records instead of CNAME records. CNAME records will not be able to point at an IP Address.
The key to making each of the sites to work is to specify ServerName correctly for each virtual server in your Apache config.
Solution 2:
Use A
record to point to the sub domains
myurl.com. A 300 123.123.123.123
api.myurl.com. A 300 123.123.123.123
app.myurl.com. A 300 123.123.123.123
preview.myurl.com. A 300 123.123.123.123
www.myurl.com. CNAME 300 myurl.com.