apache 403 forbidden 错误解决方法2008-08-25 15:33                                                            Selinux限制了访问。可以用
           # chcon -u system_u -t httpd_sys_content_t -R 目录
           为http访问增加权限

问 题的解决的办法是针对特定的目录和文件使用 chcon 来给文件贴个标签(这样说应该还算合适吧,正式的说法应该是 security context)。先用 ls -Z 看能正常访问的位置的文件和目录的标签,比如 /var/www 是 system_u:object_r:httpd_sys_content_t,然后使用

chcon -R -h -t httpd_sys_content_t

来贴标签。-R 是递归,-h 不跟随符号链接。这样 apache 应该就可以访问这个文件和目录了。vsftpd 的解决办法也是类似的。

比如:
           [root@monitor cci]# ls -Z /var/www/
           drwxr-xr-x root      root      system_u:object_r:httpd_sys_script_exec_t cgi-bin
           drwxr-xr-x root      root      system_u:object_r:httpd_sys_content_t error
           drwxr-xr-x root      root      system_u:object_r:httpd_sys_content_t html
           drwxr-xr-x root      root      system_u:object_r:httpd_sys_content_t icons
           drwxr-xr-x root      root      system_u:object_r:httpd_sys_content_t manual
           drwxr-xr-x webalize root      system_u:object_r:httpd_sys_content_t usage
           [root@monitor cc]# ls -Z /var/www/html/
           drwxr-xr-x root      root      root:object_r:root_t              cc
           -rw-r--r-- root      root      root:object_r:httpd_sys_content_t phptest.php
           [root@monitor cacti]# chcon -R -h -t httpd_sys_content_t /var/www/html/cc/