Apache 对特定域说“禁止访问此资源,您无权访问该资源。”

Apache 对特定域说“禁止访问此资源,您无权访问该资源。”

我在 AWS 上有一台服务器,为许多网站提供服务。还安装了 Webmin。

在 Apache 中,当我尝试创建一个网站时,当我使用 Web 浏览器请求它时ferrari.example.com出现错误。Forbidden. You don't have permission to access this resource.

这不是文件权限问题,因为如果我使用不同的域名(指向同一个目录),它可以正常工作。

这不是 Apache 配置问题,因为如果我只更改域名(而不更改其他配置设置),它就可以正常工作。

是的,我有一个指向我的服务器的正确 DNS 条目ferrari.example.com

不,Apache 中没有其他与域名冲突的网站。我进行了检查grep -r ferrari */etc/apache只发现了一个网站。

有谁对为什么这不起作用还有其他想法吗?

<VirtualHost *:80>
DocumentRoot /var/www/ferrari.example.com
ServerName ferrari.example.com
<Directory /var/www/ferrari.example.com>
AllowOverride All
Options None
Require all granted
</Directory>
</VirtualHost>

我想我没有安装 SELinux。

日志级别调试显示这些错误:

[Thu Sep 19 19:13:00.740101 2019] [authz_core:debug] [pid 31107] mod_authz_core.c(809): [client 204.112.96.198:13742] AH01626: authorization result of Require all denied: denied, referer: http://ferrari.example.com/
[Thu Sep 19 19:13:00.740130 2019] [authz_core:debug] [pid 31107] mod_authz_core.c(809): [client 204.112.96.198:13742] AH01626: authorization result of <RequireAny>: denied, referer: http://ferrari.example.com/
[Thu Sep 19 19:13:00.740139 2019] [authz_core:error] [pid 31107] [client 204.112.96.198:13742] AH01630: client denied by server configuration: /var/www/html/favicon.ico, referer: http://ferrari.example.com/

答案1

我遇到了同样的问题。

以下是我解决问题的方法

使用 nano 编辑器打开 apache2.conf 文件。

sudo nano /etc/apache2/apache2.conf

用这个替换常规目录设置。

<Directory />
    #Options FollowSymLinks
        Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
        Order deny,allow
        Require all granted
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>


#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>

确保目录中的虚拟主机配置文件/etc/apache2/sites-available采用这种方式

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port t$
        # 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 example.com (put your domain name here)

        ServerAdmin webmaster@localhost
        DocumentRoot /home/username/myapp (put your app root directory here)

        # 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>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

重启 Apache2 服务

sudo systemctl restart apache2

就这样。

我希望这有帮助

相关内容