V
V
vitaliyharchenko2015-07-29 12:29:47
Django
vitaliyharchenko, 2015-07-29 12:29:47

How to properly configure NGINX and Gunicorn for Django?

I deploy a django application to the server using Gunicorn according to the digitalocean instructions:
https://www.digitalocean.com/community/tutorials/h...
The application responds completely, but files from static are not loaded. What have I done wrong? Tried already a bunch of options
nginx configs

server {
        server_name test.sportcourts.ru;

        access_log off;

        location /static/ {
            root /opt/myenv/sportcourts/static/;
        }

        location / {
                proxy_pass http://127.0.0.1:8001;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM N$
        }
    }

Part of settings.py:
ALLOWED_HOSTS = ['test.sportcourts.ru', '127.0.0.1:8001']
DEBUG = True
STATIC_URL = '/static/'
STATIC_ROOT = '/opt/myenv/sportcourts/static/'

Gunicorn config:
command = '/opt/myenv/bin/gunicorn'
pythonpath = '/opt/myenv/sportcourts'
bind = '127.0.0.1:8001'
workers = 3

Project structure:
/opt
---/myenv
------gunicorn_config.py
------/bin
------/sportcourts
---------/other_apps
---- -----/sportcourts
------------settings.py
Run gunicorn with the command:
/opt/myenv/bin/gunicorn -c /opt/myenv/gunicorn_config.py sportcourts.wsgi

Collectstatic performed, there are no more ideas.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey K, 2015-07-29
@mututunus

location /static/ {
    root /opt/myenv/sportcourts/;
}

or
location /static/ {
    alias /opt/myenv/sportcourts/static/;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question