• Nginx 403 Forbidden 解决方案 史上最靠谱


    原因 1. SELinux为开启状态(enabled)

    1. 查看SELinux的状态
    sestatus
    

      如果不是 disables , 需要

    vi /etc/selinux/config
    

      将以前的 SELINUX=enforcing 改为 SELINUX=disabled ,如下所示

    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled   
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected.
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted

      保存后,reboot重启系统即可。

    注:这是个大坑!!!至于SELinux是什么请自行百度:)

    原因 2. 权限问题

      例如网站根目录为 /var/www/html/    , 首页文件为 /var/www/html/index.html

      除了index.html文件根据需求设置权限,例如

    chmod 644 /var/www/html/index.html

      必须将这个文件所在的目录设置为有 读 和 操作 的权限

    chmod -R 755 /var/www/html

    注: 这个没多大乱用,几乎所有的文件(夹)都符合需要的权限。

    原因 3. 没有指定的文件index.html等

      这个就不详细举例了,细心点不会在这里犯错的,

      在nginx配置文件里按需要写上主页名,别忘了后面的分号就行。

    index  index.php index.html;  

    ------------------------PS--------------------------

    这个问题没把我急死,文件权限修改了无数次怎么也不行,终于发现是SELinux的锅,既然暂时用不到这个东东,就将它禁用~~~

    或许更改用户组权限也可以解决这个问题,留待心情好了再看看~

    ________________END________________

  • 相关阅读:
    【VectorDemo】
    【列表迭代器:添加元素】
    【列表迭代器】
    【迭代器】
    【LinkedList】
    【list 集合的使用】
    【CollectionDemo2】
    【CollectionDemo1】
    【集合和数组的区别?】
    【到底使用那种集合?】
  • 原文地址:https://www.cnblogs.com/freelandun/p/6662982.html
Copyright © 2020-2023  润新知