Here are my settings :
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = '/home/django-projects/tshirtnation/staticfiles'
Here's my nginx configuration:
server {
server_name 77.241.197.95;
access_log off;
location /static/ {
alias /home/django-projects/tshirtnation/staticfiles/;
}
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 NAV"';
}
}
I've run python manage.py collectstatic
and it has copied all static files. I run my server with gunicorn_django --bind:my-ip:8001 and everything seems to be working except for static files.
EDIT: I've run
sudo tail /var/log/nginx/error.log
and there seems to be no errors of static files not found :/
settings.py:
In the nginx configurations(/etc/nginx/sites-enabled/default)
Then restart the nginx server:
And run gunicorn:
Serves the application on localhost or the entire local network (on port 80).
Mine looks like this, and it worked:
And in the nginx configuration, my location /static/ is above the location / like this,
And one more thing, I don't know if that matters, but I do have a 'listen' in the server{}. I'm not sure if it can help.
Check this things
1 Whether the static older is accessible by nginx, I mean the folder permission .
2 Or do this
Replace this:
with this
STATIC_ROOT = ''
And add this in settings
Don't forget to reload the nginx server.
Hope this works.
In your settings.py, put this:
You don't need this:
Your problem is that the
location /
block is always used, even after thelocation /static/
one, so everything will beproxy_pass
ed.The solution here is to use some
try_files
magic.I think browser tries to find your static in:
While nginx by default work on 80 port.
You need to define 8001 port in nginx config or run django server on 80 port.