Nginx serve static file and got 403 forbidden

后端 未结 8 950
长情又很酷
长情又很酷 2020-12-04 08:36

Just want to help somebody out. yes ,you just want to serve static file using nginx, and you got everything right in nginx.conf:

location /s         


        
8条回答
  •  失恋的感觉
    2020-12-04 08:51

    Since Nginx is handling the static files directly, it needs access to the appropriate directories. We need to give it executable permissions for our home directory.

    The safest way to do this is to add the Nginx user to our own user group. We can then add the executable permission to the group owners of our home directory, giving just enough access for Nginx to serve the files:

    CentOS / Fedora

      sudo usermod -a -G your_user nginx
    
      chmod 710 /home/your_user 
    

    Set SELinux to globally permissive mode, run:

    sudo setenforce 0

    for more info, please visit https://www.nginx.com/blog/using-nginx-plus-with-selinux/

    Ubuntu / Debian

      sudo usermod -a -G your_user www-data
    
      sudo chown -R :www-data /path/to/your/static/folder
    

提交回复
热议问题