apache 403 forbidden怎么解决


本文摘自PHP中文网,作者藏色散人,侵删。

apache 403 forbidden怎么解决

apache httpd服务器403 forbidden的问题

一、问题描述

在apache2的httpd配置中,很多情况都会出现403。

刚安装好httpd服务,当然是不会有403的问题了。主要是修改了一些配置后出现,问题描述如下:

修改了DocumentRoot目录指向后,站点出现403错误。

设置了虚拟主机目录也可能导致403。

apache的httpd服务成功启动,看起来都很正常,却没有权限访问

日志出现: access to / denied (filesystem path '/srv/lxyproject/wsgi/django.wsgi') because search permissions are missing on a component of the path

设置虚拟目录后,错误日志出现:client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi

二、分析问题及方案

下面一步步解决问题时注意错误日志内容。ok,开始。

1、httpd.conf中目录配置文件

如果显示更改了DocumentRoot,比如改为 "/usr/local/site/test" 。site目录和test目录是通过使用mkdir建立的,然后在test目录下放一个index.html。这种情况应该查看httpd.conf中配置。

你的<Directory "/usr/local/site/test">一定要和DocumentRoot一致,因为这段Directory是apache对该目录访问权限的设置,只有设置正确的目录,DocumentRoot才会生效。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

<Directory "/usr/local/site/test">

    #

    # 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.4/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.

    #

    Require all granted

</Directory>

2、目录访问权限

第一步配置正确还是出现403,检查目录配置<Directory "/usr/local/site/test">中是否有Deny from all。有则所有访问都会被拒绝,当然403了。

可以设置为Allow from all或者Require all granted来处理。

不要修改<Directory />根目录中Deny from all。

3、目录权限

如果至此还是403,可能是网站目录的权限问题。

apache要求目录具有执行权限,也就是x,要注意的是,你的目录树都应该拥有这些权限。

假如你的目录是/usr/local/site/test,那么要保证/usr,/usr/local,/usr/local/site,/usr/local/site/test这四个层级的目录都是755权限。

1

2

#chmod 755 /usr/local/site

#chmod 755 /usr/local/site/test

我犯过一个错就是只设置了最后一级目录权限,没有设置上级目录权限,导致403。

4、 虚拟目录

【这个问题我没遇到过,因为我没这样写过,网上资料这么写,可作为参考】

阅读剩余部分

相关阅读 >>

centos7下升级Apache至最新版本

Apache hadoop怎么读

Apache是干什么的

Apache怎么设置自己的ip地址

Apache与ngin服务器区别是什么

Apache修改最大并发连接数

Apache可以干什么

Apache怎么修改端口号

kali linux怎么安装Apache

Apache可以解析php吗

更多相关阅读请进入《Apache》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...