简体   繁体   English

Nginx不提供Django静态文件

[英]Nginx is not serving Django static files

I just configured my first django server for a very basic django-website. 我刚刚为一个非常基本的django网站配置了我的第一台django服务器。 I'm using Django 1.4 and Nginx 1.0.14 with supervisor and gunicorn. 我正在使用Django 1.4和Nginx 1.0.14与主管和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. 问题是Nginx没有提供静态文件,但我不知道为什么因为我第一次使用它。

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: 这是我在我的nginx配置文件中的设置:

# 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. 您不是来自Nginx的管理媒体,只是普通媒体。 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. 注意没有尾部斜杠,路径以contrib结尾。 I'm using almost exactly this code successfully in production. 我在生产中几乎完全使用了这段代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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