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
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
www.myurl.com.  CNAME   300 myurl.com.
api.myurl.com.  CNAME   300
app.myurl.com.  CNAME   300
preview.myurl.com.  CNAME   300

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.


  1. 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 all IP addresses remain the same?
  2. To test things out, could I start by changing only the data value for preview.myurl.com. without risking of compromising the rest?
  3. Once all lower level domains (e.g. api.myurl.com) point to the IP of the VM, can I point the A value of myurl.com. to a different IP without compromising the other lower level domains (api, app, preview)?
  • 2
    Without reading much more from your question, you shouldn't use CNAME records with ip-addresses but use A records instead: app.myurl.com. A 300 – HBruijn Dec 28 '16 at 18:59
  • I'll go a step further and say that CNAME records must point at a domain name, and cannot be IP addresses. I would be surprised if a DNS management system would allow you to put an IP address as the target of a CNAME record. – Dre Dec 28 '16 at 19:16
  • 2
    @Dre You can put numbers in a CNAME RR that look like an IP address, but they will be interpreted as an unqualified domain name. – Michael Hampton Dec 28 '16 at 19:18

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.

  • Thank's, thats very helpful. The only thing I'm unsure is the bit about the ServerName. What should it look like to work properly? My doubt is, is ServerName affected somehow by the way in which the DNS resolves to a particular VS? – don Dec 28 '16 at 22:12
  • 1
    If I understand you correctly, yes. The Servername is how Apache knows which VS to send the traffic to.. Let's say you have all the A records setup in your DNS, all pointing at the address. When you browse to myurl.com, your request gets sent to Apache receives the request and realizes it has a few web sites on that IP, so Apache will look closer at the request you sent and realize your browser was looking for myurl.com. Apache will look for that URL to match one of the Servername values for each VS. – Dre Dec 29 '16 at 17:43

Use A record to point to the sub domains

myurl.com.  A   300
api.myurl.com.  A   300
app.myurl.com.  A   300
preview.myurl.com.  A   300
www.myurl.com.  CNAME   300 myurl.com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.