为什么我在 ubuntu 14.04 上收到 Apache 2.4.7 的 403 权限被拒绝

为什么我在 ubuntu 14.04 上收到 Apache 2.4.7 的 403 权限被拒绝

我读过十几个不同的答案,但这些答案似乎都没有帮助。简而言之,这个问题如下:

@bos-lpqum:/var/www$ curl http://localhost/html/index.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /html/index.html
on this server.</p>
<hr> 
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 80</address>
</body></html>

当我尝试从另一台机器访问(打开正确的端口后)时出现超时。

我运行了sudo chown -R www-data:www-data /var/www,但仍然得到相同的 403。我可以提供您想要查看的任何配置文件。

我从另一台运行 apache 2.2.22 的机器上复制了我的启用站点的配置。本地我运行的是 2.4.7。

更新:权限对我来说看起来很准确:

@bos-lpqum:/var$ ls -lt
total 64
drwxr-xr-x  4 root     root     4096 May  7 23:12 centrifydc
drwxrwxrwt  2 root     root     4096 May  7 22:48 tmp
drwxrwxr-x 21 root     syslog   4096 May  7 08:00 log
drwxr-xr-x  2 root     root     4096 May  6 07:59 backups
drwxrwsrwt  2 root     whoopsie 4096 May  6 07:35 crash
drwxrwsrwt  2 root     whoopsie 4096 May  5 13:09 metrics
drwxr-xr-x 10 root     root     4096 May  5 12:53 spool
drwxr-xr-x 20 root     root     4096 May  5 12:50 cache
drwxr-xr-x 79 root     root     4096 May  5 12:50 lib
drwxr-xr-x  3 www-data www-data 4096 May  5 12:40 www
drwxr-xr-x  3 root     root     4096 May  5 12:12 dell
lrwxrwxrwx  1 root     root        4 May  4 15:41 run -> /run
drwxr-xr-x  4 root     root     4096 Mar 18 11:19 centrify
drwxr-xr-x  2 root     root     4096 Mar 18 08:19 games
lrwxrwxrwx  1 root     root        9 Mar 18 08:03 lock -> /run/lock
drwxrwsr-x  2 root     mail     4096 Mar 18 08:03 mail
drwxr-xr-x  2 root     root     4096 Mar 18 08:03 opt
drwxrwsr-x  2 root           50 4096 Apr 19  2012 local

尝试使用 https (而不是 http) 进行 curl:

$ curl https://localhost -k
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
 [email protected] to inform them of the time this error occurred,
 and  the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at localhost Port 443</address>
</body></html>

“允许所有人”在任何地方都找不到:

$ egrep -r "allow.*from" /etc/apache2/*
/etc/apache2/mods-available/info.conf:  # Uncomment and change the "192.0.2.0/24" to allow access from other hosts.
/etc/apache2/mods-available/status.conf:    # Uncomment and change the "192.0.2.0/24" to allow access from other hosts.

原始配置:

http://pastebin.com/vaHUqccf

新配置:

http://pastebin.com/mTzvDk6X

000-默认.配置:

http://pastebin.com/jJtKtHTV

答案1

在 Apache 2.2 中,该指令为allow from all,但在 Apache 2.4 中,该指令已变为。请在文档中require all granted搜索。require all granted

答案2

我没有看到<Directory>在您的配置中阻止。虽然 Apache 默认允许访问任何内容,但您的 Linux 发行版很可能附带了安全的默认配置不允许除非特别允许,否则无法访问。

最小的 Apache(2.4)虚拟主机看起来有点像这样:

<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  DocumentRoot /var/www/example.com

  <Directory "/var/www/example.com">
    Require all granted
  </Directory>
</VirtualHost>

相关内容