首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本地主机的NameVirtualHost指令警告

本地主机的NameVirtualHost指令警告
EN

Stack Overflow用户
提问于 2013-04-02 21:17:59
回答 2查看 9.2K关注 0票数 2

我已经阅读了许多帖子,并在同一IP地址上为2个站点配置了WAMP,如下所示(httpd.conf摘录):

代码语言:javascript
复制
#Tell Apache to identify which site by name
NameVirtualHost *:80

#Tell Apache to serve the default WAMP server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost 127.0.0.1>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
allow from all
order allow,deny
AllowOverride all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost 127.0.0.1>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
allow from all
order allow,deny
AllowOverride all
</Directory>

我还更改了Windows主机文件,以添加127.0.0.1、client1.localhost等。但是,当我重新启动WAMP服务时,//client1.localhost和//client2.localhost转到c:\wamp\www文件夹中的默认站点。

真的很感谢任何人的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-02 23:50:08

你在httpd.conf中包含你的vhosts.conf了吗?

取消注释httpd.conf底部附近的这一行(以‘Include’开头的那行):

代码语言:javascript
复制
# Virtual hosts - leave this commented
Include conf/extra/httpd-vhosts.conf

编辑:看起来问题是NameVirtualHostVirtualHost必须匹配,所以你不能同时使用NameVirtualHost *:80VirtualHost 127.0.0.1。相反,可以使用NameVirtualHost *:80VirtualHost *:80,或者使用NameVirtualHost 127.0.0.1:80VirtualHost 127.0.0.1

如果它们不匹配,您将看到您的评论中提到的行为,其中不匹配其他虚拟主机的虚拟主机将被命中,或者如果它们都相同,第一个虚拟主机(您的默认本地主机)将被命中。

有关更多信息,请参阅本文:Wamp Server: Multiple Virtual Hosts are not working on Windows

票数 4
EN

Stack Overflow用户

发布于 2013-04-27 09:17:01

试试这个配置,它只是你的几个小模块

代码语言:javascript
复制
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

## must be first so the the wamp menu page loads
<VirtualHost *:80>
    ServerAdmin webmaster@homemail.net
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost *:80>
   ServerName client1.localhost
   DocumentRoot "C:/wamp/www_client1"
   <Directory "C:/wamp/www_client1">
      AllowOverride All
      order Allow,Deny
      Allow from all
   </Directory>
   DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost *:80>
    ServerName client2.localhost
    DocumentRoot "C:/wamp/www_client2"
    <Directory "C:/wamp/www_client2">
        AllowOverride All
        order Allow,Deny        
        Allow from all
</Directory>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15765160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档