4

i have 3 domains pointed at my linux box, apache2 virtual hosts is set up so that each domain loads the appropriate webpage when you visit it outside of the LAN.

my trouble is trying to view the pages from the LAN.

if i go to the boxes lan ip, i get the contents of /var/www/html/

how would i go about viewing the 3 other domains that are located in /var/www/(site-name-here) through the lan?

  • 1
    apache2 virtual hosts is correctly set up obviously not :) – Simon Hayter Jun 3 '16 at 18:22
  • ok ok i'll remove the word correctly. :) – helmet648 Jun 3 '16 at 19:14
4

Your attempting to access the site using a IP address when your virtual host file is setup to use a domain name, not an IP address... so it'll throw up the default folder, in this case /var/www/html/.

Fix 1. Local Virtual host file

The most common and easy method to fix the issue would be to edit your host file within Windows or Mac, this will allow you to access all sites locally, using the domain name as you would externally...

The host file would look something like this:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#
192.168.1.1 exampleA.com
192.168.1.1 exampleB.com
192.168.1.1 exampleC.com

Fix 2. Virtual IP addresses

Since you have 3 sites and if you intend to be able to visit all of these via the internal lan IP then are faced with a greater issue of how can you tell Apache2, which site to return when you only have one IP address...

The a fix would be to use virtual IP addresses, and assign a virtual IP address to the virtual host, rather than using *.

Something like this:

# Site A
<VirtualHost 100.100.100.1>
    ServerName www.example-1.com
    DocumentRoot /var/www/exampleA
</VirtualHost>

# Site A
<VirtualHost 100.100.100.2>
    ServerName www.example-2.com
    DocumentRoot /var/www/exampleB
</VirtualHost>

# Site C
<VirtualHost 100.100.100.3>
    ServerName www.example-3.com
    DocumentRoot /var/www/exampleC
</VirtualHost>

Using the above will allow you to visit the sites using the virtual IP addresses.

Fix 3. Map folders

You can map folders as alias so that when someone visits http://100.100.100.1/exampleA they get site A, or going to /exampleB will get site B etc.

Something like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    Alias /ExampleA /var/www/exampleA
    Alias /exampleB /var/www/exampleB

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
     </Directory>
</VirtualHost>
  • didn't even think about setting my windows hosts file... thanks for all the useful info! – helmet648 Jun 3 '16 at 19:15

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.