29๐
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.
35๐
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.
- [Django]-About IP 0.0.0.0 in Django
- [Django]-What are the limitations of Django's ORM?
- [Django]-Cannot import name _uuid_generate_random in heroku django
13๐
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.confuser your_app_user
Replace
your_app_user
with appropriate unix username for your app. In this case theyour_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.
- [Django]-Django QuerySet order
- [Django]-Django โ Class Based Generic View โ "No URL to redirect to"
- [Django]-Django models, custom functions
10๐
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
)
- [Django]-Django Model Field Default to Null
- [Django]-Custom QuerySet and Manager without breaking DRY?
- [Django]-Get objects from a many to many field
10๐
The best solution in that case would be to add www-data to username group:
gpasswd -a www-data username
For your changes to work, restart nginx
nginx -s reload
- [Django]-Securing communication [Authenticity, Privacy & Integrity] with mobile app?
- [Django]-Running django tutorial tests fail โ No module named polls.tests
- [Django]-How to overcome 'Coudn't find that formation' error when adding web dynos to Heroku django app?
8๐
Try specifying a user at the top of your nginx.conf, above the server section.
user www-data;
- [Django]-Django admin: how to sort by one of the custom list_display fields that has no database field
- [Django]-Django removing object from ManyToMany relationship
- [Django]-"{% extends %}" vs "{% include %}" in Django Templates
3๐
I had the same issue no long ago. It might be a combination of factors. I found how to fix 403 access denied
by replacing the user in the nginx.conf
file.
- I deployed my website on an ubuntu server using Digital Ocean.
- I created a new user on my new ubuntu server and give admin priviliges
adduser newuser
usermod -aG sudo newuser
- I updated my new server and installed few packages
sudo apt update
sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx curl
- I followed all this beautiful instruction on how to deploy your site on Digital Ocean
- Since I changed the user and I ssh into my new server using this new user, I need to replace the user on the
nginx.conf
. By defaultnginx.conf
user iswww-data
:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
Then I replaced with my sudo user and solved my problem. ๐
user newuser;
worker_processes auto;
pid /run/nginx.pid;
- Then I restart nginx, gunicorn and postgresql(even if the last one it is not really necessary)
sudo systemctl restart nginx
sudo systemctl restart gunicorn
sudo systemctl restart postgresql
And tada.. ๐ no more issue.
- [Django]-Django internationalization language codes
- [Django]-Django Rest Framework make OnetoOne relation ship feel like it is one model
- [Django]-How to display all model fields with ModelSerializer?
2๐
Fix 403 error with Django static files on Ubuntu server.
-
Run this ->
gpasswd -a www-data your_proj_username
-
Reload nginx ->
nginx -s reload
-
Check chmod for your dirs:
/home
,/home/proj_dir
,/home/proj_dir/static
- Run this โ
stat --format '%a' /home
. Result must be 755 - Run this โ
stat --format '%a' /home/your_proj_dir/static
. Result must be 755 - Run this โ
stat --format '%a' /home/your_proj_dir
. Result must be 750
- If you have different values you can try to change this:
sudo chmod 755 /home
sudo chmod 755 /home/your_proj_dir/static
sudo chmod 750 /home/your_proj_dir
- Reload you project-server. This solve all permission errors
- [Django]-Python Asyncio in Django View
- [Django]-Django Programming error column does not exist even after running migrations
- [Django]-Django BigInteger auto-increment field as primary key?
-7๐
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.
- [Django]-Proper way to test Django signals
- [Django]-Check permission inside a template in Django
- [Django]-How do you limit list objects template side, rather than view side