Nginx: stat() failed (13: permission denied)

后端 未结 16 1837
梦谈多话
梦谈多话 2020-12-04 05:04

I am using the default config while adding the specific directory with nginx installed on my ubuntu 12.04 machine.

server {
        #listen   80; ## listen          


        
相关标签:
16条回答
  • 2020-12-04 05:37

    I faced this problem, I solved it to give permissions to nginx user and group something like this:

    chown -R nginx:nginx /username/test/static
    
    0 讨论(0)
  • 2020-12-04 05:38

    This is how i fixed this

    sudo chmod o+x /home/ec2-user
    
    0 讨论(0)
  • 2020-12-04 05:42

    I finally found my way through. In short, let's say your username is joe and you hold a website under your personal filesystem /home/joe/path/to/website.

    You literally have to tell the system that nginx is your pal.
    Place nginx in joe group :

    sudo gpasswd -a nginx joe
    

    After that if it still doesn't work, check right access of /home/joe directory. That's probably the reason why nginx can't reach the file because even if he is your friend now you have to open him the door to your house :

    sudo chmod g+x /home/joe
    

    That's it. That's literally all you have to do to give nginx access to your local files :)

    I don't think there are security concerns with this method because nginx is the high authority and only an admin can change the group. nginx can now read what's in joe directories. It's only a security breach if the holder of the nginx account is different with the user you open directory access from, but in my case I'm the holder of both parties, that is in a local context.

    0 讨论(0)
  • 2020-12-04 05:42

    I had the same issue, I am using Plesk Onyx 17 with Centos7. I could see this error in proxy_error_log under the affected domain's logs. All the dirs/files in /var/www/vhosts/ are owned by respective users (domain owners) and you can see that all of them are in psacln group. So solution was to add nginx also to this group, so he can see what he needs:

    usermod -aG psacln nginx
    

    And indeed, restart nginx and reload page with Ctrl+F5.

    0 讨论(0)
  • 2020-12-04 05:44

    This is usually the privilege problem... For me, its because i use the /root/** as the nginx root, it need higher privilege. An easy way is just move the project into a directory created by yourself.

    0 讨论(0)
  • 2020-12-04 05:46

    You may have Security-Enhanced Linux running, so add rule for that. I had permission 13 errors, even though permissions were set and user existed..

    chcon -Rt httpd_sys_content_t /username/test/static

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