zoukankan      html  css  js  c++  java
  • Apache 安装后Error 403的故障排错方法(linux)

    Apache 安装后Error 403的故障排错方法

    2018年01月07日 14:25:41

    个人分类: Linux

    一、问题描述

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

    img

    刚安装好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来处理。

    不要修改根目录中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>
    

    复制代码

    我访问

    img

    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>
    

    复制代码

  • 相关阅读:
    如何查看MySQL的当前存储引擎?
    转载mysql数据库配置优化
    redis教程
    基于 Android APP 安全测试流程
    移动APP安全测试
    自动化测试用例如何进行参数化
    分享一波免费的PPT模板下载网站
    UI自动化-滑块验证码识别 java版本
    安全测试博客汇总
    妙手回春——GRUB系统引导器恢复指南
  • 原文地址:https://www.cnblogs.com/h-gallop/p/11646032.html
Copyright © 2011-2022 走看看