PHP直播班直减600元+赠送VIP三个月(限前30名)
视频教程分类
推荐视频教程
  • php程序员小白到大牛三个月集训php程序员小白到大牛三个月集训
  • Laravel 9 学习正当时—保姆级教程,想学不会都难!Laravel 9 学习正当时—保姆级教程,想学不会都难!
  • 千万级数据并发解决方案(理论+实战)千万级数据并发解决方案(理论+实战)
  • Laravel基础与实战(模块化)Laravel基础与实战(模块化)
  • UNI-APP开发(仿饿了么)UNI-APP开发(仿饿了么)
  • 首页 >运维 >Apache > 正文

    apache 403 forbidden怎么解决

    原创2019-12-16 14:34:172555 关注公众号:每天精选资源文章推送

    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才会生效。

    <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权限。

    #chmod 755 /usr/local/site
    #chmod 755 /usr/local/site/test

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

    4、 虚拟目录

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

    如果设置的是虚拟目录,那么你需要在httpd.conf中定义一个虚拟目录,而且像极了如下的片段:

    Alias /folder "/usr/local/folder"                       
    <Directory "/usr/local/folder">                         
        Options FollowSymLinks                            
        AllowOverride None                              
        Order deny,allow                               
        Deny from all                                 
        Allow from 127.0.0.1 192.168.1.1                       
    </Directory>

    如果是这一种情况,而且你写得类似我上面的代码,三处folder都是一样一样的,那绝对会是403!怎么解决呢,就是把跟在Alias后面斜杠后面的那串改了,改成什么,不要和虚拟目录的文件夹同名就好,然后我就可以用改过后的虚拟目录访问了,当然,改文件夹也行,只要你不怕麻烦,只要Alias后面的虚拟目录定义字符(红色)和实际文件夹名(黑色)不相同就OK。

    5、selinux的问题

    如果依然是403,那就是selinux在作怪了,于是,你可以把你的目录进行一下selinux权限设置。

    今天我遇到的就是这个问题了。

    #chcon -R -t httpd_sys_content_t /usr/local/site
    #chcon -R -t httpd_sys_content_t /usr/local/site/test

    网上资料说不过,这一步大多不会发生。但我的问题确实是,可能跟系统有关,具体原理还不是很懂。

    6、wsgi的问题

    我的虚拟主机配置为:

    <VirtualHost *:80>
    WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgi
    Alias /static/ /srv/lxyproject/collectedstatic/
    ServerName 10.1.101.31
    #ServerName example.com
    #ServerAlias www.example.com
    <Directory /srv/lxyproject/collectedstatic>
      Options Indexes  FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    <Directory /srv/lxyproject/wsgi/>
        Allow from all
    </Directory>
    ErrorLog   /etc/httpd/logs/lxyproject.error.log
    LogLevel warn
    </VirtualHost>

    我访问

    log报错:

    client denied by server configuration: /srv/lxyproject/wsgi/django.wsgi

    解决办法:

    修改<Directory /srv/lxyproject/wsgi/>中Allow from all为:Require all granted。

    这个问题是因为版本的原因,

    我的httpd版本为:

    [root@yl-web conf.d]# rpm -qa |grep httpd
    httpd-devel-2.4.6-31.el7.centos.x86_64
    httpd-tools-2.4.6-31.el7.centos.x86_64
    httpd-2.4.6-31.el7.centos.x86_64

    而2.3以下版本用Allow from all,2.3及以上版本为Require all granted。

    <Directory /home/aettool/aet/apache>
      <IfVersion < 2.3 >
       Order allow,deny
       Allow from all
      </IfVersion>
      <IfVersion >= 2.3>
       Require all granted
      </IfVersion>
    </Directory>

    以上就是apache 403 forbidden怎么解决的详细内容,更多请关注php中文网其它相关文章!

    PHP小白到大牛线上直播班第二十期

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

  • 相关标签:apache
  • 相关文章

    相关视频


    专题推荐