How do I access internal network virtual hosts in Apache?

5,225

As you have discovered, if you use the IP address of the server, you will be taken to the first virtual instance in the list.

I just add entries to my local hosts file that use the virtual server names.

Some xDSL routers (eg: Draytek's) will allow you to use URLS that refer back to sites hosted on the local LAN - this is called DNS loopback - so another 'fix' is to change the router. This can be a viable choice for, say, a business, where it's an easier to manage solution than updating all the local hosts files.

Share:
5,225

Related videos on Youtube

Mr Fox
Author by

Mr Fox

Updated on September 17, 2022

Comments

  • Mr Fox
    Mr Fox over 1 year

    This might be a stupid question but I'm tired and can't find a solution.

    I currently have an Apache Web Server running on Ubuntu 10.4 and I use a DynDNS service to make them accessible to the outside world via a domain and/or subdomain.

    My configs currently look like this:

    <VirtualHost *:80>
    
        ServerAdmin     <obscured>@<obscured>.com
        ServerName      <subdomain>.<obscured>.com
        ServerAlias     <subdomain>
    
        DocumentRoot    /<obscured>/<subdomain>
    
        <Directory />
            Options         FollowSymLinks
            AllowOverride   None
        </Directory>
    
        <Directory /<obscured>/<subdomain>>
            Options         Indexes FollowSymLinks MultiViews
            AllowOverride   All
            Order           Allow,Deny
            Allow           From All
        </Directory>
    
        ErrorLog    ${APACHE_LOG_DIR}/error.$host.log
        CustomLog   ${APACHE_LOG_DIR}/access.$host.log combined
    
    </VirtualHost>
    

    This works fine from access outside of the network and all subdomains resolve to the correct directory.

    The problem I am having is with accessing a subdomain over my internal network.

    I can access the Web Server using the server's IP address: http://192.168.1.123/ but this always takes me to the same virtual host and I don't know how to distinguish between different virtual hosts (different subdomains).

    Ideally I would like to access the same subdomains using http://<subdomain>/ where <subdomain> is the same as the subdomain attached to the external domain name.

    Any ideas?

  • Mr Fox
    Mr Fox about 13 years
    Sorry I updated my question for clarification. It works fine externally.
  • Randolf Richardson
    Randolf Richardson about 13 years
    What is the private IP? Make sure Apache is listening on that too.
  • Mr Fox
    Mr Fox about 13 years
    Updated again, I can access it using the IP directly but I don't know how to distinguish between different vhosts running different subdomains.
  • Randolf Richardson
    Randolf Richardson about 13 years
    Hint: Check your "Listen" directive in the main httpd.conf file -- this needs to cover everything you need to serve on (specifying port 80 without an IP address should catch everything though).
  • Randolf Richardson
    Randolf Richardson about 13 years
    The "ServerName" directive will take the main one. If you have additional hosts, then add a "ServerAlias" directive after that to support the additional ones in the same VirtualHost stanza/container.
  • Mr Fox
    Mr Fox about 13 years
    I tried adding ServerAlias <subdomain> but still nothing.
  • Randolf Richardson
    Randolf Richardson about 13 years
    Which IP address is your hostname resolving to? Is your VirtualHost actually configured to handle that IP address?