禁止Apache2虚拟主机403?

时间:2013-07-14 03:58:41

标签: ubuntu apache2 virtualhost http-status-code-403

我在桌面上运行ubuntu 13.04 64bit,我安装了Apache2,MySQL和PHP等。

我希望将我的网络根目录放在/home/afflicto/public_html而不是/var/www。 所以我接受了这个指南:
http://www.maketecheasier.com/install-and-configure-apache-in-ubuntu/2011/03/09
(我从“配置不同的网站”做了所有事情),因为我更喜欢解决方案。

以下是我的所作所为:
安装了Apache2,MySQL等。
/etc/apache2/sites-avaliable/default复制到/etc/apache2/sites-available/afflicto。然后编辑它,它现在看起来如下:

/ etc / apache2 / sites-available / afflicto

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /home/afflicto/public_html
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /home/afflicto/public_html/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>  

我做了sudo a2dissite default && sudo a2ensite afflicto && sudo service apache2 restart

我在index.php中创建了index.html/home/afflicto/public_html/test/ 访问localhost/testlocalhost/test/index.html等时,我收到403禁止错误。

我做错了什么?提前谢谢。

更新1
我已将public_html目录的所有者设置为www-datasudo chmod -R +x public_html && sudo chmod -R 777 public_html
仍然是403错误。

这是apache错误日志的输出:

[Sun Jul 14 06:10:32 2013] [error] [client 127.0.0.1] (13)Permission denied: access to / denied

[Sun Jul 14 06:10:32 2013] [error] [client 127.0.0.1] (13)Permission denied: access to /favicon.ico denied

4 个答案:

答案 0 :(得分:105)

我遇到了这个问题。但我不喜欢将我的主目录组更改为www-data的想法。可以通过修改virtualHost的配置文件来简单地解决此问题。 只需配置Directory标记以包含这些

<Directory "your directory here">
   Order allow,deny
   Allow from all
   Require all granted
</Directory>

我猜Require all granted是一项新功能;默认值为denied

请参阅此页面以获取更多信息:http://httpd.apache.org/docs/current/mod/core.html#directory

答案 1 :(得分:20)

原来我不仅要chmod /home/afflicto/public_html而且还要/home/afflicto/目录。

怪异。

答案 2 :(得分:0)

这些选项对我有用:

 Options Indexes FollowSymLinks
 AllowOverride All   
 Require all granted

答案 3 :(得分:0)

这是另一个答案,打算添加一个更简单的解释。假设您要提供一个名为“ main”的文件,该文件位于/var/www/testwebsite目录(已配置并启用的虚拟主机的DocumentRoot)中。现在假设我们希望Apache Web服务器只能访问“ main”文件,而不能访问其他文件(例如main可能是我们的Web应用程序的入口点),那么这意味着apache Web服务器必须是其中的所有者。该文件。因此chown www-data:www-data /var/www/testwebsite/main必须做到这一点。 (注意:www-data既是用户名,也是apache与其他文件进行交互时使用的组名(实际上,在Ubuntu以外的发行版上,这可能是一个不同的名称,在这种情况下,它可以只需在apache2.conf中查找))。同样,如果“主”文件无权读取/执行,则必须将其授予apache的用户和组:chmod 770 /var/www/testwebsite/main。这为文件“主”所有者的用户(www-data)和组(www-data)提供了以下权限:读/写/执行(4 + 2 + 1 = 7),而其他用户则没有权限。现在,单个文件(主文件)可以由Apache运行,而我们可以对/var/www/testwebsite目录中的所有其他文件进行任何其他严格的限制。

相关问题