Django/Nginx 403 Error on new static files

Multi tool use
Django/Nginx 403 Error on new static files
Can't figure out why, but after collecting new static files (collectstatic
), nginx throws 403 Error.
collectstatic
New files have different permissions from old static files.
-rw-rw-r-- 1 django django 115206 Jul 9 15:23 dom.jpg
-rw-r----- 1 django django 884 Jul 23 20:42 error.svg
-rw-rw-r-- 1 django django 308934 Mar 11 16:30 header.bmp
-rw-rw-r-- 1 django django 20188 Mar 11 16:30 header.jpg
-rw-r----- 1 django django 910 Jul 23 20:42 success.svg
-rw-rw-r-- 1 django django 1826 Jul 9 15:23 user.svg
As you can see - error.svg
and success.svg
have different permissions, that's why nginx
throws 403.
error.svg
success.svg
nginx
Do you know how to fix this? I don't want just change permission for existing files, I want universal solution so this never happens again.
top
returns this:
9143 django 20 0 59124 6580 4904 S 0.0 1.3 0:07.44 gunicorn
9149 django 20 0 213640 67600 8692 S 0.0 13.5 0:07.91 gunicorn
9150 django 20 0 215224 68680 8520 S 0.0 13.7 0:08.95 gunicorn
9151 django 20 0 215056 68420 8512 S 0.0 13.7 0:09.32 gunicorn
32386 root 20 0 126132 1168 684 S 0.0 0.2 0:00.00 nginx
32387 www-data 20 0 127076 4580 3308 S 0.0 0.9 0:03.43 nginx
django
Can you let your server run the command
whoami
and print this to a logfile (or something similar). I have the idea that the server is not running as django
.– Willem Van Onsem
3 hours ago
whoami
django
@WillemVanOnsem I'm not sure which server - nginx or gunicorn, I've added results of top command at the bottom of the question.
– Milano Slesarik
3 hours ago
Well the top
nginx
is - if I recall correctly - the one you invoke, that will obtain the port (since ports below 1024
require root access), but then it passes control to a child running with another user, to reduce the risk. What if you add www-data
to the django
group?– Willem Van Onsem
3 hours ago
nginx
1024
www-data
django
For example with
sudo usermod -a -G django www-data
– Willem Van Onsem
3 hours ago
sudo usermod -a -G django www-data
1 Answer
1
Did you tried chmod 644 on this files ?
I think that if I read the question correctly, this was actually what the OP wanted to avoid. Furthermore since the owner is the
django
user, if the server is configured correctly, it should work.– Willem Van Onsem
3 hours ago
django
I read too fast
– Philoow
3 hours ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Do you run your webserver with the
django
user?– Willem Van Onsem
4 hours ago