Apache配置虚拟主机后让其他电脑访问

关于Apache配置虚拟主机后在局域网中让其他电脑访问

#test1#
NameVirtualHost *:80    
    ServerName  www.t1.com
    DocumentRoot "/Users/me/www/test1"    
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    
#test2#
NameVirtualHost *:80    
    ServerName  www.t2.com
    DocumentRoot "/Users/me/www/test2"    
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    
#错误显示#
php_flag display_errors        on
php_value error_reporting       2039

如上所示,共配置了2个虚拟主机:

www.t1.com

www.t2.com

如果我本机 的IP地址是:192.168.1.123

那么在 局域网内访问此IP看到的网站就是上面配置中第一个配置的虚拟主机,本案例中就是:www.t1.com

如果想要访问别的虚拟主机,那么只需要把对应的主机放置到最前面即可!

【备注】

Options FollowSymLinks 表示不列出目录下的文件,如果要列出文件列表,则使用 Options Indexes FollowSymLinks

C:\Windows\System32\drivers\etc 目录下 hosts文件中:最后添加一行:127.0.0.1 www.t1.com

Linux 系统下,是在 /etc/hosts 文件中。(本地路由优先!)