我正在配置我的apache服务器。在httpd.conf中,我将DocumentRoot设置如下:
DocumentRoot "D:/phpwwwroot"
我将目录节点设置如下:
<Directory "D:/phpwwwroot">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
目前,我还没有启用虚拟主机。我访问了网址:http://localhost:8080/
,一切都很好。
接下来,我尝试设置虚拟主机。我取消了对虚拟主机的注释。如下:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
我的httpd-vhosts.conf如下:
NameVirtualHost *:8080
<VirtualHost *:8080>
ServerName www.testphp1.com
DocumentRoot "D:VirtualRoot"
DirectoryIndex index.shtml index.html index.htm index.php
<Directory "D:VirtualRoot">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName www.testphp2.com
DocumentRoot "D:VirtualRoot1"
DirectoryIndex index.shtml index.html index.htm index.php
<Directory "D:VirtualRoot1">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我还编辑了主机文件来更正映射,你应该知道我的意思:
127.0.0.1 www.testphp1.com
127.0.0.1 www.testphp2.com
接下来重新启动apache服务器,访问以下网址:
http://www.testphp1.com:8080/
http://www.testphp2.com:8080/
一切都很好。它们被映射到了正确的文件夹。
提出了一个新的问题,当我尝试访问http://localhost:8080/
时,它会出现在第一个虚拟主机www.testphp1.com上。我的意思是页面显示www.testphp1.com
显示的内容。
"主主机"似乎不起作用。
这是怎么发生的?如何修复
当您使用IP访问服务器时,情况也是一样的。它将显示第一个使用此IP的活动网站(此处将localhost
视为IP)。你可以先定义主网站来修复它。
您还需要添加主主机,例如:
<VirtualHost *:8080>
ServerName localhost
DocumentRoot "D:/phpwwwroot"
</VirtualHost>