【问题标题】:Multiple virtual host in wampwamp中的多个虚拟主机
【发布时间】:2015-06-22 14:20:05
【问题描述】:

我正在尝试在 wamp 中创建多个虚拟主机,但是当我添加第二个虚拟主机时,它会显示 wamp 主页。

这是我的主机文件:

#localhost name resolution is handled within DNS itself.
#127.0.0.1       localhost
#::1             localhost
127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::localhost
::www.site1.com
::www.aksharen.com

这是我的 httpd-vhosts.conf 文件:

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost        
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/websites/www.site1.com/public"
    ServerName "www.site1.com"
    <Directory C:/websites/www.site1.com>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/websites/www.aksharen.com/public"
    ServerName "www.aksharen.com"
    <Directory C:/websites/www.aksharen.com>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

我的第一个站点,即 www.site1.com 运行良好。

【问题讨论】:

  • @NishantSolanki — 如果您不想要多个虚拟主机,为什么还要虚拟主机?虚拟主机的全部意义在于在单个服务器上支持多个网站!
  • @Quentin 嘿抱歉,我误会了,我以为她想在本地电脑上创建虚拟服务器.. :P
  • @Vaidehi.. 你好,你有没有从你的httpd.conf 文件中取消注释Include conf/extra/httpd-vhosts.conf 这一行?请参考此链接thegeekstuff.com/2011/07/apache-virtual-host
  • 您可以使用httpd -S验证虚拟配置语法
  • 请选择一个答案

标签: php apache wamp virtualhost


【解决方案1】:

你犯了一些错误

第一个

127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::localhost
::www.site1.com
::www.aksharen.com

尝试将其更改为

127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::1  localhost
::1  site1.com
::1  aksharen.com

其次,我可以建议对您的虚拟主机定义进行这些更改:-

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/websites/www.site1.com/public"
    ServerName site1.com
    ServerAlias www.site1.com
    <Directory "C:/websites/www.site1.com/public">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/websites/www.aksharen.com/public"
    ServerName aksharen.com
    ServerAlias www.aksharen.com
    <Directory "C:/websites/www.aksharen.com/public">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

【讨论】:

    【解决方案2】:

    为您的虚拟主机使用环回地址 ips。即每个虚拟主机都应该有自己独特的环回 ip。例如,您的主机文件应类似于:

    127.0.0.100      drupal.fox
    127.0.0.2      play.fox
    127.0.0.3     cake241.fox
    

    所以你的 vhosts 文件应该是这样的:

    <VirtualHost 127.0.0.100:80>
    <Directory "c:/ampps/www/drupal.fox">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    allow from All
    </Directory>
    ServerName drupal.fox
    ServerAlias drupal.fox
    ScriptAlias /cgi-bin/ "c:/ampps/www/drupal.fox/cgi-bin/"
    DocumentRoot "c:/ampps/www/drupal.fox"
    ErrorLog "C:/ampps/apache/logs/drupal.fox.err"
    CustomLog "C:/ampps/apache/logs/drupal.fox.log" combined
    </VirtualHost>
    

    当然,您必须创建新的虚拟主机条目,其 IP 与主机文件中的 IP 相同。

    【讨论】:

    • 当您拥有唯一的域名时,为什么需要不同的 IP 地址?
    • 我只是觉得用另一个层来区分它们更清楚,因为在一些本地测试中我们可能需要从不同的URL访问同一个Web应用程序,所以在这种情况下,我可以作为drupal访问它.fox 或 127.0.0.100
    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 2012-03-27
    • 2013-03-15
    • 2014-07-15
    • 2014-09-20
    • 2012-04-06
    • 2016-05-16
    • 1970-01-01
    相关资源
    最近更新 更多