apache http 403 Forbidden error解决办法

daidaizhuzhu 2011-06-16

在配置Linux的 Apache服务时,经常会遇到http403错误,我今天配置测试时也出现了,最后解决了,总结了一下。http 403错误是拒绝访问的意思,有很多原因的。我总结的主要有4种原因!

1. 访问的文档权限不够。要755以上权限。解决方法:用命令chmod 755 /var/www/ 或其他相应目录。

2. SELinux或防火墙的原因。解决方法:先关闭SELinux和让防火墙通过WWW服务。

3. 虚拟主机配置错误。解决方法:重新配置虚拟主机或暂时关闭。

4. alias指令配置错误。(alias语法:Alias URL-path file-path|directory-path)

   解决方法如下: 打开apache的配置文件httpd.conf,查看所有的alias指令,若指令中的URL-path末尾包含/,则file-path或dir-path的末尾也需要包含/,如下所示:

alias /server1   /var/server1 //正确

alias /server1/ /var/server1/ //正确

alias /server1/ /var/server1 //错误

5. DocumentRoot的设置。解决方法如下:

打开 apache的配置文件httpd.conf,找到这段代码:

<Directory />

OptionsFollowSymLinks

AllowOverrideNone

Orderdeny,allow

Denyfromall

</Directory>

有时候由于配置了php后,这里的“Deny from all”已经拒绝了一切连接。把该行改成“allow from all”,修改后的代码如下,问题解决。

<Directory />

OptionsFollowSymLinks

AllowOverrideNone

Orderdeny,allow

Allowfromall

</Directory>

6. For bugzilla installation

You should check the user in httpd.conf and localconfig, and make sure the same user in those two files:

6.1 For httpd.conf as below:

#

#Ifyouwishhttpdtorunasadifferentuserorgroup,youmustrun

#httpdasrootinitiallyanditwillswitch.

#

#User/Group:Thename(or#number)oftheuser/grouptorunhttpdas.

#Itisusuallygoodpracticetocreateadedicateduserandgroupfor

#runninghttpd,aswithmostsystemservices.

#

Userdaemon

Group daemon

6.2 For localconfig

# This is the group your web server runs as.

#IfyouhaveaWindowsbox,ignorethissetting.

#Ifyoudonothaveaccesstothegroupyourwebserverrunsunder,

#setthisto"".Ifyoudosetthisto"",thenyourBugzillainstallation

#willbe_VERY_insecure,becausesomefileswillbeworldreadable/writable,

#andsoanyonewhocangetlocalaccesstoyourmachinecandowhateverthey

#want.Youshouldonlyhavethissetto""ifthisisatestinginstallation

#andyoucannotsetthisupanyotherway.YOUHAVEBEENWARNED!

#Ifyousetthistoanythingotherthan"",youwillneedtorunchecksetup.pl

#asroot,orasauserwhoisamemberofthespecifiedgroup.

$webservergroup = 'daemon';

6.3 Change the ownership by the chown command as below:

Chown -R root:daemon bugs/

相关推荐