H
H
Held69912021-09-29 21:37:45
Nginx
Held6991, 2021-09-29 21:37:45

How to solve the file access problem?

Hello, I configured everything correctly, set the correct paths, but for some reason a similar error pops up:
6154b2ea9e201369682538.png
nginx settings

server {
listen 80;
server_name IP;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/melody;
}

location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}


Project structure :
[email protected]:~/melody# ls -alah
total 40K
drwxr-xr-x 7 root root 4.0K Sep 29 19:37 .
drwx------ 5 root root 4.0K Sep 29 19:07 ..
-rw-r--r-- 1 root root    0 Sep 29 13:29 __init__.py
-rw-r--r-- 1 root root  663 Sep 29 13:29 manage.py
-rw-r--r-- 1 root root   39 Sep 29 13:29 Procfile
-rw-r--r-- 1 root root  347 Sep 29 13:29 requirements.txt
drwxr-xr-x 4 root root 4.0K Sep 29 14:31 reserveflats
drwxr-xr-x 8 root root 4.0K Sep 29 19:26 static
drwxr-xr-x 2 root root 4.0K Sep 29 19:07 templates
drwxr-xr-x 4 root root 4.0K Sep 29 13:33 venv
drwxr-xr-x 4 root root 4.0K Sep 29 13:52 website

Thank you all in advance for your help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-09-29
@Held6991

Your static is located in the home directory of root, naturally there is no access for anyone.
You need to create a separate user, run the application on his behalf, and from a directory that belongs to him.

mkdir -pv /var/www/username/data/www/site.ru/{static,media} && \
useradd --home-dir /var/www/username/data --user-group www-data && \
chown -R username:www-data /var/www/username && \
chmod g+r /var/www/username

Don't forget to change the username in unit-e systemd. Make systemctl daemon-reloadand restart the service.
The gunicorn socket can also be placed in the user's home directory.
From under root, you can log in as a different user usingsudo -i -u username

H
Held6991, 2021-09-29
@Held6991

Lynn "Coffeeman" Thank you
chmod 755 ..solved the problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question