Nginx is throwing an 403 Forbidden on Static Files

后端 未结 6 1699
野性不改
野性不改 2020-12-14 19:10

I have a django app, python 2.7 with gunicorn and nginx.

Nginx is throwing a 403 Forbidden Error, if I try to view anything in my static fo

相关标签:
6条回答
  • 2020-12-14 19:15

    MacOs El Capitan: At the top of nginx.conf write user username group_name

    My user name is Kamil so i write:

    user Kamil staff;
    

    (word 'staff' is very important in macOS). This do the trick. After that you don't need to change any permission in your project folder and files.

    0 讨论(0)
  • 2020-12-14 19:18

    It seems the web server user doesn't have read permissions to the static files. You can solve this in 2 ways:

    1. (easiest, safer) run the nginx as you app user instead of default nginx user. To do this, add the following in nginx.conf

      user your_app_user
      

      Replace your_app_user with appropriate unix username for your app. In this case the your_app_user already has necessary permissions to the static content.

    2. Another way would be to to grant permissions for the web server user to the static dir.

    0 讨论(0)
  • 2020-12-14 19:20

    After hours upon hours following so many articles, I ran across : http://nicholasorr.com/blog/2008/07/22/nginx-engine-x-what-a-pain-in-the-bum/

    which had a comment to chmod the whole django app dir, so I did:

    sudo chmod -R myapp
    

    This fixed it. Unbelievable!

    Thanks to those who offered solutions to fix this.

    0 讨论(0)
  • 2020-12-14 19:21

    Try specifying a user at the top of your nginx.conf, above the server section.

    user www-data;
    
    0 讨论(0)
  • 2020-12-14 19:30

    The minimum fix that worked for me is:

    sudo chmod -R 664 /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/
    sudo chmod -R a+X /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/
    

    (BTW, in my case the static folder is called collected_static)

    0 讨论(0)
  • 2020-12-14 19:37

    It appears the user nginx is running as (nginx?) is missing privileges to read the local file /home/ubuntu/virtualenv/myapp/myapp/homelaunch/static/img/templated/home/img.png. You probably wanna check file permissions as well as permissions on the directories in the hierarchy.

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