Apache [forbidden 403]错误的解决办法 |
| 发布时间: 2012/8/11 9:39:22 |
|
今天准备试着在Apache服务器上配置用户目录(User Directory)。遇到一个棘手的问题,现将配置过程和问题及其解决总结如下:
1、常规的配置: 在web用户目录下建立public_html目录,并将权限设置为755: 修改/etc/http/httpd.conf: 2、测试、问题出现: Forbidden Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.54 (Fedora) Server at 127.0.0.1 Port 80 一般出现这个问题,直观地会想到的目录的存取权限问题,查了很久,调了很久也没有解决问题。其间曾想到是否Selinux的问题,进去看了一圈,没有发现什么要改的地方。(后来的事实证明,有时候直觉是很准的,能否找到答案,区别往往是:是否在直觉上走的更深入)。 3、问题的解决 4、关联知识的总结: Fedora Core 5 SELinux FAQ If you do not already have a ~/public_html directory, create it and populate it with the files and folders to be served. cd ~mkdir public_htmlcp /path/to/content ~/public_html At this point, httpd is configured to serve the contents, but you still receive a 403 forbidden error. This is because httpd is not allowed to read the security type for the directory and files as they are created in the user's home directory. Change the security context of the folder and its contents recursively using the -R option: ls -Z -d public_html/drwxrwxr-x auser auser user_u:object_r:user_home_t public_htmlchcon -R -t httpd_user_content_t public_html/ls -Z -d public_html/drwxrwxr-x auser auser user_u:object_r:httpd_user_content_t public_html/ls -Z public_html/-rw-rw-r-- auser auser user_u:object_r:httpd_user_content_t bar.html-rw-rw-r-- auser auser user_u:object_r:httpd_user_content_t baz.html-rw-rw-r-- auser auser user_u:object_r:httpd_user_content_t foo.html You may notice at a later date that the user field, set here to user_u, is changed to system_u. This does not affect how the targeted policy works. The field that matters is the type field. 本文出自:亿恩科技【www.enkj.com】 |
京公网安备41019702002023号