title: External access to apache virtual host
body: <p>I've set up an Apache server on a computer in my home network and enabled name-based virtual hosting. </p>
  
  <p>I've configured the host files on my local network machines, enabled port forwarding on the router and configured the DNS.</p>
  
  <p>I would like to be able to access the virtual host both from within the network and also externally.</p>
  
  <p><code>192.168.0.2</code> is the IP address of the virtual host and <code>1.2.3.4</code> is the external IP address.</p>
  
  <p>With the following configuration in httpd-vhosts.conf:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName www.my-hostname.com
      ServerAlias my-hostname.com
      DocumentRoot "&lt;path-to-doc-root&gt;"
          &lt;Directory "&lt;path-to-doc-root&gt;""&gt;
              Options Indexes FollowSymLinks
              AllowOverride All
              Order allow,deny
              Allow from all
          &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>From the virtual host machine:</p>
  
  <ul>
  <li><code>192.168.0.2</code> gets me the apache main server 'It works!' page.</li>
  <li><code>1.2.3.4</code> gets me 'The requested URL /UI was not found on this server.'</li>
  <li><code>my-hostname.com</code> gets me the virtual host.</li>
  </ul>
  
  <p>From a different machine inside the network:</p>
  
  <ul>
  <li><code>192.168.0.2</code> gets me the apache main server 'It works!' page.</li>
  <li><code>1.2.3.4</code> gets me the apache main server 'It works!' page.</li>
  <li><code>my-hostname.com</code> gets me the virtual host.</li>
  </ul>
  
  <p>From an external machine:</p>
  
  <ul>
  <li><code>1.2.3.4</code> gets me the apache main server 'It works!' page.</li>
  <li><code>my-hostname.com</code> gets me the apache main server 'It works!' page.</li>
  </ul>
  
  <p>If I change the configuration (as suggested on the apache website) to:</p>
  
  <pre><code>&lt;VirtualHost 192.168.0.2  1.2.3.4&gt;
      ServerName www.my-hostname.com
      ServerAlias my-hostname.com
      DocumentRoot "&lt;path-to-doc-root&gt;"
          &lt;Directory "&lt;path-to-doc-root&gt;""&gt;
              Options Indexes FollowSymLinks
              AllowOverride All
              Order allow,deny
              Allow from all
          &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>From the virtual host machine:</p>
  
  <ul>
  <li><code>192.168.0.2</code> gets me the apache main server 'It works!' page.</li>
  <li><code>1.2.3.4</code> gets me 'The requested URL /UI was not found on this server.'</li>
  <li>my-hostname.com gets me the apache main server 'It works!' page.</li>
  </ul>
  
  <p>From a different machine inside the network:</p>
  
  <ul>
  <li><code>192.168.0.2</code> gets me the virtual host.</li>
  <li><code>1.2.3.4</code> gets me the apache main server 'It works!' page.</li>
  <li><code>my-hostname.com</code> gets me the virtual host.</li>
  </ul>
  
  <p>From an external machine:</p>
  
  <ul>
  <li><code>1.2.3.4</code> gets me the virtual host.</li>
  <li><code>my-hostname.com</code> gets me the virtual host.</li>
  </ul>
  
  <p>Can some please explain why:</p>
  
  <ul>
  <li>the change to the virtual host file has the impact it does.</li>
  <li>what is the correct configuration.</li>
  <li>I can't access either server from the virtual host machine with with either configuration using <code>1.2.3.4</code>.</li>
  </ul>
  
  <p>This is driving me nuts. Any help would be really appreciated.</p>