I have django 3.1 installed on digitalocean ubuntu 20.04 and nginx/1.18.0 (Ubuntu) and using rest api
Following are my static and media files settings.
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
STATIC_ROOT = BASE_DIR / 'static_in_env'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
Following is my Digital Ocean Nginx Conf
location /static/ {
root /home/username/backend/src;
}
location /media {
root /home/username/backend/src;
}
it’s giving me forbidden on even files less than 100kb.
Also After checking Nginx logs I found that Permission Denied Error.
5
Answers
Hello Harsh Sonawane try put slash after media like this
Your config seems to be OK.
What you should check is you have installed NGINX as a root user or the user that has access to the files you are trying to serve.
Please try:
if that does not work try changing "root" for "alias" like this:
I solved this error by:
First:-
chmod -R 777 media
(outside of media folder)Second:- in
/etc/nginx/sites-available/project.conf
to
Third:- reload your service file and nginx
sudo systemd restart project.service
sudo systemd restart nginx
Make DIR and Change permissions on Ubuntu server:
and then change settings.py