Debian 上的 Apache2:访问本地网站时被禁止

Debian 上的 Apache2:访问本地网站时被禁止

因此,我想将文件夹 /home/web 配置为我的网络服务器,因为那里有代表我正在开发的所有网站的文件夹。我最近从 Centos 切换到 Debian,所以我正在重新安装所有内容。

我当前的网页是 fh。权限如下(这是在 /home/web 内:

drwxrwxr-x.  6 ariela www-data 4096 May 15 06:33 fh

我已经修改了 /etc/apache2/apach2.conf,以便默认的 /var/www/html 目录如下所示:

<Directory /home/web>
        Order allow,deny
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

之后我将 /etc/apache2/sites-available/000-default.conf 更改为如下形式:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /home/web

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

但在将我的浏览器重定向到 localhost/fh 之后,我收到了禁止消息,并且日志显示:

[Wed May 15 07:24:53.129930 2019] [authz_core:error] [pid 8159] [client ::1:56998] AH01630: client denied by server configuration: /home/web/fh
[Wed May 15 07:24:53.183159 2019] [authz_core:error] [pid 8159] [client ::1:56998] AH01630: client denied by server configuration: /home/web/favicon.ico, referer: http://localhost/fh

我错过了什么?

答案1

问题有两个方面:

  • 目录名称有拼写错误(howe 与 home)
  • 您添加了一行Order allow,deny,这是旧式的访问控制,并且需要相应allow from all类型的规则,而不是新式的Require all granted

因此,修复拼写错误,删除订单行,它就可以正常工作了。

答案2

首先,您应该将<Directory>块添加到<VirtualHost>配置中。无需编辑/etc/apache2/apache2.conf

Apache 2.2

如果您使用的是 Apache 2.2,那么Require all granted语法无效。

http://httpd.apache.org/docs/2.4/mod/mod_access_compat.html#order

Deny,Allow

首先,否定评估指令;如果匹配,则拒绝请求除非它也匹配允许指令。任何不符合任何允许或者否定指令是允许的。

因此,如果我们Order Deny,Allow在这里使用并且不指定任何AllowDeny规则,那么就允许访问。

<Directory /home/web>
    Order Deny,Allow
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

选择:

<Directory /home/web>
    Order Allow,Deny
    Allow from all
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

Apache 2.4

如果您使用的是 Apache 2.4,则OrderAllowDeny是弃用语法。请Require改用:

<Directory /home/web>
    Require all granted
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

看:https://httpd.apache.org/docs/2.4/upgrading.html#run-time

相关内容