大网数据广告活动
网站运营与故障问答

apache virtual hosts on LAN

· 52CE 我爱测

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…

问题原文

原帖链接 · helmet648 · CC BY-SA 3.0

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?

已采纳解答

原帖链接 · Simon Hayter · CC BY-SA 3.0

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>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。