Apache - 您无权访问 / 在此服务器上

Gro*_*ler 4 apache macos-sierra

clg.localhost/我收到错误:

您无权访问 / 在此服务器上。

但是,在此之后,我已经设置了我的 Apachehttpd.confsites.conf允许使用AllowOverride all和进行访问Require all granted。我还缺少什么?

版本:

$ /usr/sbin/httpd -v
Server version: Apache/2.4.23 (Unix)
Server built:   Aug  8 2016 18:10:45
Run Code Online (Sandbox Code Playgroud)

Apache httpd.conf:

DocumentRoot "/Users/danniu/Sites"
<Directory "/Users/danniu/Sites">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

...

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride all
    Require all granted     
</Directory>
Run Code Online (Sandbox Code Playgroud)

Apache 站点.conf:

# Workaround for missing Authorization header under CGI/FastCGI Apache:
<IfModule setenvif_module>
  SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>

# Serve ~/Sites at http://localhost
ServerName localhost

<VirtualHost *:80>
   ServerName clg.localhost
   DocumentRoot /Users/danniu/Sites/CLG/CLG-dev
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我想可能httpd.conf没有被正确地拾取,所以我直接在虚拟主机中指定了根,遇到了同样的问题。

<VirtualHost *:80>
   ServerName clg.localhost
   DocumentRoot /Users/danniu/Sites/CLG/CLG-dev
   # Set access permission
   <Directory "/Users/danniu/Sites/CLG/CLG-dev">
     Require all granted
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

ezr*_*a-s 5

/ 是一个目录,因此如果您没有使用 DirectoryIndex 指向的索引文件,例如 index.html,并且您没有启用索引,因为您没有启用,Apache 无法显示您的文档根目录的内容.

注意你有 Options FollowSymLinks Multiviews

解决方案是,在选项中为“目录列表”添加如下索引(这取决于之前加载的 mod_autoindex):

Options FollowSymLinks Multiviews Indexes
Run Code Online (Sandbox Code Playgroud)

如果你想加载一个默认文件,例如 index.html,DirectoryIndex 默认查找 index.html,所以添加它,或者如果它在其他地方覆盖它的行为:

DirectoryIndex index.html 
Run Code Online (Sandbox Code Playgroud)