Невозможно загрузить файлы stati c в приложение DJANGO с использованием AWS EC2 - PullRequest
0 голосов
/ 20 июня 2020

Я успешно развернул приложение Django на AWS EC2, используя gunicorn и NGINX сервер. Но файлы stati c даже после настройки файла django .conf в / etc / nginx / sites-available / не загружаются в шаблоны.

django .conf файл:

server{
        listen 80;
        server_name my_server_name;

        location / {
                include proxy_params;
                proxy_pass http://unix:/home/ubuntu/learning-aws/app.sock;
        }

        location /static/ {
                autoindex on;
                alias /home/ubuntu/learning-aws/myprofile/core/static/;
        }
}

файл gunicorn.conf:

[program:gunicorn]
directory=/home/ubuntu/learning-aws/myprofile
command=/home/ubuntu/env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/learning-aws/app.sock myprofile.wsgi:application
autostart=true
autorestart=true
stderr_logfile=/var/log/gunicorn/gunicorn.err.log
stdout_logfile=/var/log/gunicorn/gunicorn.out.log

[group:guni]
programs:gunicorn

файл settings.py:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'core/static/')

Используемые теги шаблона (например, base. html):

{% static 'plugins/bootstrap/bootstrap.min.css' %}

1 Ответ

0 голосов
/ 20 июня 2020

Это была очень простая ошибка, адрес файлов stati c был неправильным:

    # changed
    # alias /home/ubuntu/learning-aws/myprofile/core/static/;
    # to
    alias /home/ubuntu/learning-aws/core/static/;

И изменил порядок расположения root ('/') и stati c ('/ stati c') из-за приоритета системы. на:

    server{
        listen 80;
        server_name my_server_name;

        location / {
                include proxy_params;
                proxy_pass http://unix:/home/ubuntu/learning-aws/app.sock;
        }

        location /static/ {
                autoindex on;
                alias /home/ubuntu/learning-aws/myprofile/core/static/;
        }
    }

...