代码之家  ›  专栏  ›  技术社区  ›  tleo

在apache中服务多个根目录

  •  0
  • tleo  · 技术社区  · 8 年前

    我希望我的两个站点:flowers.loc(drupal 8)和honey.loc(drupal 7)在apache上本地工作(v:2.234)。

    flowers.loc的第一个目录:

    Sites/drupal8/docroot
    

    honey.loc的第二个目录:

    Sites/drupal7/docroot
    

    我在httpd,apache配置文件中有这个设置:

    <VirtualHost *:80>
      DirectoryIndex index.html index.php
      DocumentRoot /User/Vizzaro/Sites
    
      <Directory "/User/Vizzaro/Sites">
      Options FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
      </Directory>
    </VirtualHost>
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Ralf E.    8 年前

    看一看 https://httpd.apache.org/docs/2.2/vhosts/examples.html 了解如何设置虚拟主机。配置文件只有一个虚拟主机条目,但每个站点需要一个条目。而且您的配置缺少服务器名。试试这个:(未经测试)

    # Ensure that Apache listens on port 80
    Listen 80
    
    # Listen for virtual host requests on all IP addresses
    NameVirtualHost *:80
    
    <VirtualHost *:80>
        ServerName flowers.loc
        DocumentRoot /User/Vizzaro/Sites/drupal8/docroot
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName honey.loc
        DocumentRoot /User/Vizzaro/Sites/drupal7/docroot
    
        # Other directives here
    </VirtualHost>
    

    确保honey.loc和flowers.loc都指向运行apache的机器的ip。尝试 ping flowers.loc -如果这会导致如下错误 Name or service not known 您可能需要编辑主机文件来修复它。