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
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.
It seems the web server user doesn't have read permissions to the static files. You can solve this in 2 ways:
(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.
Another way would be to to grant permissions for the web server user to the static dir.
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.
Try specifying a user at the top of your nginx.conf, above the server section.
user www-data;
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
)
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.