Why does Nginx return a 403 even though all permissions are set properly?

前端 未结 15 2515
逝去的感伤
逝去的感伤 2020-12-12 09:54

I have Nginx setup and displaying the test page properly. If I try to change the root path, I get a 403 Forbidden error, even though all permissions are identical. Additiona

15条回答
  •  情歌与酒
    2020-12-12 10:23

    There are 2 possible reasons for denied access:

    1. Access is denied by DAC. Double check user, group and file permissions. Make sure the nginx process, when running as the user specified in its config file, can access the new html root path.

    2. Access is denied by MAC. The most widely used of such is SELinux. To check whether it caused the problem, you can stop the nginx process and run this command:

      setenforce Permissive
      

      Then start nginx again to see if access is granted.

      Alternatively, you can check the file context:

      setenforce Enforcing
      ls -Zd /usr/share/nginx/html /var/www/html
      

      If the two contexts differ, you may need to change the context for the new html root path:

      chcon -R -t httpd_sys_content_t /var/www/html
      

      Restart nginx and see if it works fine. If so, you can make the change permanent:

      semanage fcontext -a -t httpd_sys_content_t '/var/www/html(/.*)?'
      restorecon -Rv /var/www/html
      

      Some of these commands need to be run as root.

提交回复
热议问题