简体   繁体   中英

Nginx is not serving Django static files

I just configured my first django server for a very basic django-website. I'm using Django 1.4 and Nginx 1.0.14 with supervisor and gunicorn.

The problem is that Nginx is not serving the static files as suposed, but I don't know the why because is my first time using it.

This is the path where really lives my static files:

/home/cristian/envs/santalupe.com/santalupe/santalupe/static

And this is the setting I've in my nginx config file:

# Django admin media.
location /media/ {
autoindex on;
    alias /home/cristian/envs/santalupe.com/lib/python2.7/site-packages/django/contrib/admin/static/;
}

# Site media
location /static/ {
autoindex on;
    alias /home/cristian/envs/santalupe.com/santalupe/santalupe/static/;
}

Please let me know what I need to do in this case because I have not idea about the real problem.

也许manage.py collectstatic在服务器上帮助你?

You aren't serving the admin media from Nginx, just normal media. Try something like:

location /admin/media/ {
    # this changes depending on your python version
    root /home/cristian/envs/santalupe.com/lib/python2.7/site-packages/django/contrib;
}

Note how there's no trailing slash and the path ends at contrib. I'm using almost exactly this code successfully in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM