apache 报403 Forbidden错误解决方法

    文章来源:万象互联 更新时间:2015-6-10 15:02:37
分享:

Apache,版本2.2.8,安装完成后,进行相关测试;
配置了下php的php.in文件,再次localhost打开发现错误:
HTTP 错误 403 - 禁止访问,即403 Forbidden:You don't have permission to access / on this server.

可能是权限不足引起的问题。

403 Forbidden 解决方法:

打开apache的配置文件httpd.conf,逐行检查。
找到:

代码如下:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>


由于配置了php后,此处“Deny from all”为拒绝一切连接。

把此行修改为 “Allow from all”,即可解决问题。

修改后的代码为:

代码如下:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
allow from all
</Directory>

浏览器里打开http://localhost,显示it works!问题解决。

总结:
在apache服务器中,遇到403禁止访问时,重点关注下apache的httpd.conf配置文件中,是否有“Deny from all”这样的代码。
这个可能是修改了某些配置文件后,重启apache,被自动更改的。

附,另外一个apache 403错误的例子。

apache 403错误,显示信息如下:
您无权查看该网页
您可能没有权限用您提供的凭据查看此目录或网页
如果您确信能够查看该目录或网页,请尝试使用 192.168.1.5 主页上所列的电子邮件地址或电话与网站联系。
可以单击搜索,寻找 Internet 上的信息。

HTTP 错误 403 - 禁止访问
Internet Explorer

去掉显示友好信息的钩后显示Forbidden You don't have permission to access \ on this server.
检查了一遍配置文件httpd.conf,找到这么一段:

代码如下:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
deny from all
Satisfy all
</Directory>

然后试着把deny from all中的deny改成了allow,保存后重起了apache,访问测试网站完全正常了。
APACHE升级到2.2版本之后,提供和支持不少模块的支持,性能和安全上也有不少改进。
以前配置好apache的httpd.conf之后,即可使用。
但现在必须额外对这个文件进行其他方面的配置,不然会出现 http 403权限问题错误。

解决方法。
以下为httpd.conf文件的其中一段原代码。
把下面代码红色标志进行更改:

代码如下:
<Directory "E:/wamp/www">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# [url]http://httpd.apache.org/docs/2.2/mod/core.html#options[/url]
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride all
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>

更改为 Allow from all ,也就是所有访问允许通过。

下面是补充:

关键错误:You don't have permission to access / on this server
打开网页,结果访问提示:403错误!关闭了IE的"显示友好的HTTP错误",显示没有权限访问(You don't have permission to access / on this server)!

403 Forbidden主要原因分析

1你的IP被列入黑名单
2你在一定时间内过多地访问此网站(一般是用采集程序),被防火墙拒绝访问了
3网站域名解析到了空间,但空间未绑定此域名
4你的网页脚本文件在当前目录下没有执行权限
5在不允许写/创建文件的目录中执行了创建/写文件操作
6服务器繁忙,同一IP地址发送请求过多,遭到服务器智能屏蔽

END网站出现403 Forbidden解决办法

用以下命令修改文件夹安全属性
chcon -R -t httpd_user_content_t public_html/

所用命令解析:

ls -Z -d public_html/
#显示文件/目录的安全语境-Z, --context
Display security context so it fits on most displays. Displays only mode, user, group, security context and file name.-d, --directory
list directory entries instead of contents, and do not dereference symbolic links

chcon -R -t httpd_user_content_t public_html/
#修改文件/目录的安全语境-R, --recursive
change files and directories recursively-t, --type
set type TYPE in the target security context

END其他解决办法:

重建dns缓存就行
在运行中输入cmd,然后输入ipconfig /flushdns即可
或HTTP 错误 403 - 限制为仅本地主机访问 Internet 服务管理器 (HTML)
HTTP 错误 403 403.1 禁止:禁止执行访问
如果从并不允许执行程序的目录中执行 CGI、ISAPI 或其他执行程序就可能引起此错误。
如果问题依然存在,请与 Web 服务器的管理员联系。
HTTP 错误 403 403.2 禁止:禁止读取访问
如果没有可用的默认网页或未启用此目录的目录浏览,或者试图显示驻留在只标记为执行或脚本权限的目录中的 HTML 页时就会导致此错误。
如果问题依然存在,请与 Web 服务器的管理员联系。
HTTP 错误 403 403.3 禁止:禁止写访问
如果试图上载或修改不允许写访问的目录中的文件,就会导致此问题。
如果问题依然存在,请与 Web 服务器的管理员联系。
HTTP 错误 403 403.4 禁止:需要 SSL
此错误表明试图访问的网页受安全套接字层(SSL)的保护。要查看,必须在试图访问的地址前输入 https:// 以启用 SSL。
如果问题依然存在,请与 Web 服务器的管理员联系。
HTTP 错误 403 403.5 禁止:需要 SSL 128
此错误消息表明您试图访问的资源受 128 位的安全套接字层(SSL)保护。要查看此资源,需要有支持此 SSL 层的浏览器。
请确认浏览器是否支持 128 位 SSL 安全性。如果支持,就与 Web 服务器的管理员联系,并报告问题。403.6 禁止:拒绝 IP 地址

我想着大概是没有权限去访问该目录,因为一般情况下,NTFS对访问权限控制的很严格的!
于是打开目录,一看,访问权限居然是everyone的完全控制!那用户在文件夹访问权限上是绝对没有问题了!肯定是apache的配置问题了,于是上网搜索,找到如下相关信息用于修改权限.

以下为引用的内容:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>

根据配置文件提示,此设置是用于修改Apache对所有目录的访问权限的,如果任意修改,可能会带来安全隐患的!那我们来看看到底是什么在作祟,让我们无法访问网页的吧!
Deny from all 有点英文基础的都可以看的出来,这里是关键:拒绝所有!
将Deny改为Allow试试!(因为可能会存在大小写敏感的问题,所以推荐用首字母大写,有兴趣的可以自己尝试小写!)一下通过了,但是这样配置的话服务器安全性会...
于是我继续往下看配置文件!


发现了以下内容
#
# This should be changed to whatever you set DocumentRoot to.
#
以上这行注释的意思:无论你的服务器根目录设置为什么,你都必须保证此处配置保持一致!

以下为引用的内容:
<Directory "默认目录">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>

再将以上的"默认目录"设置为"目标目录",(当然已经将对所有权限访问的设置修改为拒绝了!)刷新一下页面,OK,通过了!

版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/7793.html
在线咨询
  • 在线时间
  • 8:00-21:00