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

前端 未结 15 2415
逝去的感伤
逝去的感伤 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.

    0 讨论(0)
  • 2020-12-12 10:23

    well seems logical, all files are root user, try changing it to nginx user, just wanted to make sure it's not a listing permission denied first.

    sudo chown -R nginx:nginx /var/www/html
    
    0 讨论(0)
  • 2020-12-12 10:23

    Work fine for me on nginx

    semanage permissive -a httpd_t
    
    0 讨论(0)
  • 2020-12-12 10:24

    The folks using the /home/{user} directory to serve their website need to provide a chmod 755 access on their /home/{user} directory to make this work .

    Also , if SELinux is enabled on the server please use the below mentioned commands :-

    1. sudo setsebool -P httpd_can_network_connect on
    2. chcon -Rt httpd_sys_content_t /path/to/www
    0 讨论(0)
  • 2020-12-12 10:24

    Modify the file nginx.conf, change the user name to your account name, and restart nginx.it work !

    0 讨论(0)
  • 2020-12-12 10:26

    I was using:

    sudo service nginx start
    

    If I use:

    sudo nginx 
    

    ...everything works fine. Can anyone explain the difference between these two?

    0 讨论(0)
提交回复
热议问题