Apache [forbidden 403]錯(cuò)誤的解決辦法 |
發(fā)布時(shí)間: 2012/8/11 9:39:22 |
今天準(zhǔn)備試著在Apache服務(wù)器上配置用戶目錄(User Directory)。遇到一個(gè)棘手的問題,現(xiàn)將配置過程和問題及其解決總結(jié)如下:
1、常規(guī)的配置: 在web用戶目錄下建立public_html目錄,并將權(quán)限設(shè)置為755: 修改/etc/http/httpd.conf: 2、測(cè)試、問題出現(xiàn): 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 一般出現(xiàn)這個(gè)問題,直觀地會(huì)想到的目錄的存取權(quán)限問題,查了很久,調(diào)了很久也沒有解決問題。其間曾想到是否Selinux的問題,進(jìn)去看了一圈,沒有發(fā)現(xiàn)什么要改的地方。(后來的事實(shí)證明,有時(shí)候直覺是很準(zhǔn)的,能否找到答案,區(qū)別往往是:是否在直覺上走的更深入)。 3、問題的解決 4、關(guān)聯(lián)知識(shí)的總結(jié): 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. 本文出自:億恩科技【1tcdy.com】 服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] |