X
X
xxx2017-05-01 20:32:18
Django
xxx, 2017-05-01 20:32:18

I'm trying to set up django+uWSGI+nginx. Doesn't recognize static?

I'm trying to deploy junga on a VPS.
I follow this guide
https://habrahabr.ru/post/226419/
Installed everything, everything works, ngnix works on port 80.
The matter is that at me static and media is not serviced. I get 404. Although, as I understand it, I should see the file. File structure:
мой_ip:80/media/file.png

[email protected]:~/uwsgi/venv/mysite# ls
db.sqlite3  media   mysite_nginx.conf  static	uwsgi_params
manage.py   mysite  mysite.sock        test.py

mysite_nginx.conf :
# mysite_nginx.conf

upstream django {
    # server unix:///root/uwsgi/venv/mysite/mysite.sock; # взаимодействи$
    server 127.0.0.1:8001; # взаимодействие с uwsgi через веб-порт
}

# конфигурация веб-сервера
server {
    # порт, который будет слушать веб-сервер в ожидании запросов от поль$
    listen      80;
    # доменное имя
    server_name     мой_ip; # замените на собственный домен или $
    charset     utf-8;

    # максимальный размер загружаемых на сервер данных
    client_max_body_size 75M;
# обслуживание медиа файлов и статики
    location /media  {
        alias /root/uwsgi/venv/mysite/media;  # расположение медиафайлов$
    }

    location /static {
        alias /root/uwsgi/venv/mysite/static;  # расположение статики (п$

    }

    # Остальные запросы перенаправляются в Django приложение
    location / {
        uwsgi_pass  django;
        include     /root/uwsgi/venv/mysite/uwsgi_params; # файл uwsgi_p$
    }
}

Added to setting.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")

What is wrong that static is not processed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-05-01
@Heavy10110

First, slashes at the end of paths

location /static/ {
    alias /root/uwsgi/venv/mysite/static/;
}

Secondly, I strongly doubt that nginx is running as root for you, and, accordingly, it does not have access to /root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question