【问题标题】:Multiple Document Roots based on directory?基于目录的多个文档根?
【发布时间】:2015-03-08 21:21:38
【问题描述】:

我的服务器结构是这样的:

|- var
   |-- www
       |--- website1
       |--- website2
       |--- website3

我目前正在处理website1,但我发现当我提交我的一个 Ajax 表单时,它返回以下错误:

http://www.website.com/signup: The requested URL /signup was not found on this server.

当它应该在http://www.website.com/website1/signup 下查看时。

这是我目前在apache2.conf 中添加的内容:

Alias /website1 "/var/www/website1/public"
<Directory /var/www/website1>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

我的 DocumentRoot 在我的 VirtualHosts 中设置为 /var/www。我该如何解决这个问题?

【问题讨论】:

    标签: apache ubuntu configuration directory document-root


    【解决方案1】:

    您必须使用 Apache 的虚拟主机。

    在您的 Apache 配置中:

    # Ensure that Apache listens on port 80
    Listen 80
    
    # Listen for virtual host requests on all IP addresses
    NameVirtualHost *:80
    
    <VirtualHost *:80>
    DocumentRoot /www/example1
    ServerName www.example.com
    
    # Other directives here
    
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot /www/example2
    ServerName www.example.org
    
    # Other directives here
    
    </VirtualHost>
    

    【讨论】:

      【解决方案2】:

      这行不通。您将Alias 指令与Virtual Host 混淆了。

      您所说的www.website1.com 是主机名,而不是网址的目录部分。因此 Alias 指令不会捕获。 Alias 指令允许您通过Alias /folder1 ... 之类的指令将http://www.website.com/folder1 之类的内容映射到本地文件系统中的任意位置。不多。它看不到请求的主机,因为它位于主机配置内部

      相反,您需要为每个要为其提供内容的主机名/域名设置一个虚拟主机。如果您还没有设置虚拟主机,那么 http 服务器将回退到默认主机,也就是您所说的 www.website.com。 apache http 服务器的所有选项都以出色的质量记录在案。我建议您查看该文档:http://httpd.apache.org/docs/2.2/vhosts/


      在这里准确地说:您所描述的可以实际上通过url重写来完成。但这会很痛苦,而且非常不透明。虚拟主机是要走的路。

      【讨论】:

      • 我该如何修改我的 VirtualHost 以使其正常工作?
      • 好吧,在你的http服务器的配置里面。我建议你看看文档:httpd.apache.org/docs/2.2/vhosts
      猜你喜欢
      • 2023-03-10
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 2011-05-06
      相关资源
      最近更新 更多