I have a VPS that has a web app on it and a website. The web app and the website have separate cPanels.

Default root directory for web app is: /home/webapp/public_html
Default root directory for website is: /home/website/public_html

I would like my main domain example.com to take the user to the website, and a subdomain called subdomain.example.com to take the user to the webapp.

I first went into my DNS settings and created an A Record for my domain, example.com, that points to my VPS' IP address.

I then logged in with my root account and created two VirtualHosts in /etc/httpd/conf/httpd.config:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /home/website/public_html
ServerName www.example.com
ServerAlias example.com 

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /home/webapp/public_html
ServerName subdomain.example.com
ServerAlias subdomain.example.com 

Lastly, I restarted Apache and tried accessing my domain and subdomain, but to my surprise, I am taken to the default cgi-sys/defaultwebpage.cgi page. This is the same page that I'm taken to when I go to my IP address directly.

What am I doing wrong?

My OS is CentOS 6.

  • Out of interest why do you want to use www. with a sub-domain? just seems your purposely making the domain longer without any benefit. Nov 22, 2018 at 19:01
  • Ah you're right. I shoudn't be doing that. Regardless, it seems like my virtualhosts are being completely ignored. Nov 22, 2018 at 19:07
  • 2
    Your subdomain has the same document root ("website", not "webapp"). However, like you say, it does look like your "virtualhosts are being completely ignored". The problem may lie elsewhere in your server config. Where are these vHost containers included? Where is the default CGI page you are seeing defined?
    – DocRoot
    Nov 23, 2018 at 0:49
  • @DocRoot that was a silly typo on my part when I asked the question. The vHost containers are included in /etc/httpd/conf/httpd.conf. I also tried it a different way by creating the sites-available and sites-enabled folders, with a file named example.com.conf for the website virtualhost and another named subdomain.example.com.conf for the webapp. Then I created a sym link inside sites-enabled. This doesn't seem to work either. Regarding your second question, I managed to change the root folder for the IP, so that now it displays /home/ instead. Nov 23, 2018 at 5:59
  • What version of Apache are you on? "I managed to change the root folder for the IP" - What do you mean exactly? Did you change the DocumentRoot (and appropriate perms) in the server config? Before or after you created these vHosts? "Then I created a sym link..." - how was this included in the main server config?
    – DocRoot
    Nov 25, 2018 at 12:55

1 Answer 1


First issue is that you've set both of your VirtualHost configs to use DocumentRoot /home/website/public_html -- one should be /home/webapp/public_html.

Next issue sounds like DNS, you mention adding one A record for example.com. Did you add A or CNAME records for subdomain.example.com and www.subdomain.example.com as well?

  • 2
    The first issue is actually a typo just here in my question. I edited it right now to correct the mistake. Regarding the next issue, I only added a single A record, but shouldn't it at least work for my main domain then, and not the subdomain? It doesn't work for either of them. Nov 23, 2018 at 5:52
  • Did you also add an A or CNAME record for www.example.com? I suggest adding all DNS records, waiting for DNS to propagate and then restarting your web server. Since you have ServerName set as "www.example.com", if a DNS record for that doesn't exist, it may not work properly.
    – Migrateq
    Nov 23, 2018 at 14:16
  • 1
    @RichardZack If it was a DNS issue then they wouldn't get the "default" server page?
    – DocRoot
    Nov 25, 2018 at 12:57
  • @DocRoot not necessarily, as some DNS providers use wildcards, ie. *.domain.com which may point to a different address. In this case, LeuName said he only added one DNS record, so unless he added a wildcard, it's likely that DNS resolution is the issue here. LeuName should confirm all DNS records have been properly added.
    – Migrateq
    Nov 26, 2018 at 2:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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