【问题标题】:Is Directory relative to local server path or public URL path?Directory 是相对于本地服务器路径还是公共 URL 路径?
【发布时间】:2018-07-23 20:00:42
【问题描述】:

我了解DocumentRoot 指的是服务器的本地路径(在磁盘上),即与

<VirtualHost :80>
ServerName example.com
DocumentRoot /home/www/mysite1/

浏览http://example.com/foo/index.html 将访问服务器上的/home/www/mysite1/foo/index.html

那么,我应该使用(有时似乎可行):

<Directory "/">
Require all granted
</Directory>

(引用/,即服务器文件系统的根目录是不是很奇怪?)

或者我应该像这样将DocumentRoot 复制/粘贴到Directory 中:

DocumentRoot /home/www/mysite1/
<Directory "/home/www/mysite1/">
Require all granted
</Directory>

?

如果是这样,每次修改DocumentRoot 时都必须复制/粘贴到Directory,这很烦人,为什么需要这种重复 配置路径?有没有办法说Require all grantedfor all而不必复制路径?

【问题讨论】:

    标签: apache apache2 apache2.4


    【解决方案1】:

    请参阅 Apache 手册中的 Configuration Sections

    &lt;Directory&gt; 确实是指文件系统路径。

    您可以使用&lt;Location&gt;为整个网站指定规则,与文件系统上的位置无关。

    【讨论】:

    • 谢谢。你能举一个Location的例子吗?我应该怎么做而不是&lt;Directory "/home/www/mysite1/"&gt; Require all granted &lt;/Directory&gt; 以避免重复文件系统路径?
    • 语法相同。 &lt;Location "/"&gt;,在我链接的手册中有例子。
    • 感谢@Quentin。所以基本上我能记住&lt;Directory FileSystemPath&gt;&lt;Location URLPath&gt;,这是一个好的经验法则吗?
    【解决方案2】:

    我使用了这个设置

    <VirtualHost *:80>
        ServerName seminarium.loc
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/seminarium.loc/public
    
        <Directory /var/www/seminarium.loc/public>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
    
       ErrorLog /var/www/seminarium.loc/error.log
       CustomLog /var/www/seminarium.loc/access.log combined
    </VirtualHost>
    

    目录中的路径指定将应用选项的目录。排除可能的冲突是很自然的,最好指定 DocumentRoot 的路径,就好像有几个带有“/”的站点它们将相互覆盖选项

    【讨论】:

    • 谢谢,你能解释一下它是如何工作的吗? (相对于问题)
    • 所以每次都必须将 DocumentRoot 路径复制/粘贴到目录路径中,才能设置 Require all grant?难道不复制路径就没有办法了吗?
    • 您不需要在 {site}.conf 中指定 Directory 块并将它们添加到 /etc/apache2/default.conf 对于所有网站的父目录示例 /var/www
    • default.conf 中的默认目录是什么?
    • 取决于您存储网站的位置在我的情况下,它是 /var/www/ 。目录 www 有我所有网站的目录: /var/www/site1/ /var/www/site2/ ...
    猜你喜欢
    • 2011-11-25
    • 2015-11-13
    • 2019-09-09
    • 1970-01-01
    • 2018-09-17
    • 2014-03-09
    • 2011-10-16
    • 1970-01-01
    • 2012-08-24
    相关资源
    最近更新 更多