更改 DocumentRoot 目录后出现 403 禁止访问 Apache 2.4.6

更改 DocumentRoot 目录后出现 403 禁止访问 Apache 2.4.6

所以我刚刚安装了一台装有 Ubuntu 13.10 的虚拟机。我想在更新我的 ubuntu 12.04 服务器之前先试用一下 apache 2.4.6。我希望我的文档根目录位于我的主文件夹中,因此我在etc/apache2/sites-available/000-default.conf

当我这样做时,我只收到被禁止的消息。我将新文件夹权限设置为 777,但仍然被禁止。我甚至在新目录中放置了一个 index.html 文件,该文件只显示 hello world,但什么也没有。这是我的 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/everett/webroot

<Directory /home/everett/webroot>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>


# 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

答案1

我遇到了完全相同的问题,并且是这样解决的:

首先,我按照Ubuntu 服务器指南页面

  1. 前往终端并复制将默认虚拟主机配置更改为新配置(sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mynewsite.conf
  2. 编辑此新文件(sudo gedit /etc/apache2/sites-available/mynewsite.conf)并更改文档根目录到您自己的(保存并关闭..)
  3. 使能够这个新的配置文件(sudo a2ensite mynewsite.conf)和禁用默认值 ( sudo a2dissite 000-default.conf)
  4. 编辑 apache2.conf(sudo gedit /etc/apache2/apache2.conf)并将默认部分更改为:( <Directory [write_your_dir_here]> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>保存并关闭..)
  5. 重新启动 Apache2 ( sudo service apache2 restart)

如果它已经起作用了:太棒了!


如果不是,那么您应该检查每个命名基础是否都<VirtualHost *:80>需要一个不同的ServerName集合,包括000-default.conf它是否存在。您可以apachectl -S在终端中运行以查看所有内容的快速列表。


如果仍然不起作用,那么您应该检查您的目录(以及通向它的完整路径!)是否具有读取和执行权限。权限(接收)。

  1. 转到你的根目录(cd /)并执行ls -l你可以看到类似的操作drwxr-xr-x 14 root root 4096 mei 1 01:24 [your_directory]
  2. 所有通向 www 文件夹的目录都应具有“drwxr-xr-x”权限,如果没有,您可以使用以下方法进行更改sudo chmod -R a+rx [your_directory]

如果仍然无法使其工作,您应该检查 apache 错误日志(sudo gedit /var/log/apache2/error.log)并进一步挖掘...

祝你好运!

答案2

亲爱的,我想通知您,您正在更改默认的 apache 配置。

从 000-default.conf 文件中删除这行。

<Directory /home/everett/webroot>
选项 FollowSymLinks MultiViews
AllowOverride 所有
顺序允许、拒绝
要求所有授予
</Directory>

打开您的 apache.conf 文件(/etc/apache2/apache.conf)并找到目录或转到第 172 行。您将在其中找到“目录 /var/www/”定义您的目录“/home/everett/webroot”,在此处保存并重新启动 apache 并刷新您的网页。

相关内容