title: Apache Multiple Sub Domains With One IP Address
body: <p>This has probably been asked but I can't find a straight answer, or the ones I found don't work.</p>
  
  <p>I have one domain <strong>mydomain.com</strong>, resolving to an IP; let's call it 8.8.8.8. The DNS settings also point two subdomains to that IP address with an A record. These are <strong>dev.mydomain.com</strong> and <strong>staging.mydomain.com</strong>. Both have an A-record pointing to 8.8.8.8.</p>
  
  <p>On the server (8.8.8.8) I have two virtual hosts files. These are as follows:</p>
  
  <p><strong>staging.mydomain.com.conf</strong></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName  staging.mydomain.com
      DocumentRoot /var/www/html/mydomain.com/staging/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>And...</p>
  
  <p><strong>dev.mydomain.com.conf</strong></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName  dev.mydomain.com
      DocumentRoot /var/www/html/mydomain.com/dev/
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong><em>The problem is:</em></strong></p>
  
  <p>Regardless of whether I visit <em><a href="http://staging.mydomain.com" rel="noreferrer">http://staging.mydomain.com</a></em> or <em><a href="http://dev.mydomain.com" rel="noreferrer">http://dev.mydomain.com</a></em>, I always land on <em>staging.mydomain.com</em> (Apache serves these files).</p>
  
  <p>I have restarted Apache and even the server. If I change the order of the .conf files so that dev is first, I always see that. Any suggestions would be so appreciated. Thanks!</p>
  
  <hr>
  
  <h2><strong>update</strong></h2>
  
  <p>I find myself back at this problem again! If you <em>know</em> that your syntax is correct, you might have a bad symlink. Delete it and recreate again, restarting apache in-between. I just did this and it solved hours of head-scratching. On <code>CentOS</code> you can check your available vhosts with <code>httpd -S</code></p>
  
  <h2><strong>update 2</strong></h2>
  
  <p>I've also found this issue to exist when the apache <strong>log</strong> files for the virtual host don't exist, or aren't writable.</p>