启用了Apache2 userdir,但仍然无权访问


9

我试图在我的Kubuntu 13.04笔记本电脑上设置一个apache服务器。我已经安装了apache2软件包和sudo a2enmod userdir; sudo service apache2 restart,但是当我访问时http://localhost/~user,仍然显示类似以下内容:

Forbidden

You don't have permission to access /~user on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

的结果 tail /var/log/apache2/access.log

127.0.0.1 - - [02/Aug/2013:16:22:01 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:16:22:02 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:17:35:30 +0200] "GET /~kaiyin HTTP/1.1" 403 501 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:17:35:30 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:17:35:30 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:17:36:26 +0200] "GET /favicon.ico HTTP/1.1" 404 499 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:17:36:26 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:21:05:17 +0200] "GET /~kaiyin HTTP/1.1" 403 501 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:21:05:17 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"
127.0.0.1 - - [02/Aug/2013:21:05:17 +0200] "GET /favicon.ico HTTP/1.1" 404 498 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"

的结果 tail /var/log/apache2/error.log

[Fri Aug 02 21:05:17 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:05:17 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:06:54 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:06:54 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:06:59 2013] [error] [client 127.0.0.1] (13)Permission denied: access to /~kaiyin denied
[Fri Aug 02 21:06:59 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:06:59 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:07:17 2013] [error] [client 127.0.0.1] (13)Permission denied: access to /~kaiyin denied
[Fri Aug 02 21:07:17 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Fri Aug 02 21:07:17 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico

您有public_html用户目录吗?运行apache的用户是否有权阅读它?
jordanm

@jordanm是的,我已经将它设置为755,也试过777
QED

Answers:


8

public_html目录需要有自己的权限,这样使用户Apache正在运行的可以访问它:

$ chmod -R 755 ~/public_html

还是不行?

如果查看您的Apache错误日志,您可能会看到如下一行:

[2013年8月2日星期五21:06:59] [错误] [客户端127.0.0.1](13)权限被拒绝:无法访问/〜kaiyin

这说明在此示例中,Apache没有导航到用户目录(〜kaiyin)的权限。

如何解决这个问题?

您需要确保为Apache所属的组设置了读取+执行位,或者在用户目录上也设置了其他读取+执行位,以便Apache可以访问public_html下面的文件夹。

/home
|-- [drwxr-x---]  /home/sam

/home/sam
|-- [drwxr-xr-x]  /home/sam/public_html

参考文献


我已经做到了,但是我仍然禁止使用403。
QED

@CravingSpirit-在apache日志(/var/log/httpd/access.log)和(/var/log/httpd/error.log)尾部查看是否还有其他消息。
slm

我已将日志添加到帖子中。
2013年

@CravingSpirit-注意〜kaiyin`上的访问被拒绝了吗?Apache的用户无权访问用户的顶级目录。您需要具有读取和执行权限,以便它可以访问它们。
slm

2
实际上,您几乎可以肯定不需要755。711甚至710组www-data应该在父母的身上做public_html;如果您不需要文件列表,它也会在public_html上执行,否则Apache也需要读取(因此是755/750,而不是711/710)。
CVn

1
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root

  <Directory /home/*/public_html>
    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch
    <Limit GET POST OPTIONS>
      # Apache <= 2.2:
      #Order allow,deny
      #Allow from all

      # Apache >= 2.4:
      Require all granted
    </Limit>
    <LimitExcept GET POST OPTIONS>
      # Apache <= 2.2:
      #Order deny,allow
      #Deny from all

      # Apache >= 2.4:
      Require all denied
    </LimitExcept>
  </Directory>
</IfModule>

确保在中具有正确的设置/etc/apache2/mods-enabled/userdir.conf。chmodding public_html之后,我被拒绝了权限,然后决定检查userdir.conf。我注意到有针对较早版本和较新版本的设置。我知道我正在运行最新的软件,因此启用了较新的设置,现在一切正常


感谢您提供Apache <= 2.2信息,这就是为什么它对我不起作用,而这正是我所需要的!
Wowfunhappy

0

您也可以使用/etc/hosts文件来消除对临时URL的需要。如果主题或插件(如果有)中有完整URL的引用,则该网站将不会以正确的格式显示内容。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.