Django + nginx + uwsgi不显示静态

时间:2014-11-16 19:23:09

标签: python django nginx static uwsgi

我有一个Django项目并尝试使用nginx和uwsgi进行部署(现在已经有一周了)。 我可以访问服务器,但它不显示图片和CSS。 nginx提供静态文件(例如localhost:8000 / static / images / image.png有效)但在localhost:8001 / nothing(此页面应显示image.png)。

这是我的nginx.conf

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    #server unix:///home/serveur/www/gems/GEMS/gems.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name 192.168.0.119; # substitute your machine's IP address or FQ
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/serveur/www/gems/GEMS/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/serveur/www/gems/GEMS/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/serveur/www/gems/uwsgi_params; # the uwsgi_params file you installed
    }
}

settings.py:

TEMPLATE_DIRS = ('/home/serveur/www/gems/GEMS/templates'),
STATIC_URL = '/static/' #'/home/serveur/www/gems/GEMS/static/'
STATIC_ROOT = "/home/serveur/www/gems/GEMS/static/" #os.path.join(BASE_DIR, "static/")
MEDIA_ROOT = '/home/serveur/www/gems/GEMS/static/media'
STATICFILES_DIR = ('/home/serveur/www/gems/GEMS/static')
import django.contrib.auth
django.contrib.auth.LOGIN_URL = '/'

wsgi.py:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "GEMS.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我用:

启动uwsgi
    uwsgi --http :8001 --wsgi-file GEMS/wsgi.py --chdir /home/serveur/www/gems/GEMS --virtualenv /home/serveur/www/gems --chmod-socket=666

有没有人有想法?

由于

1 个答案:

答案 0 :(得分:0)

从它的外观来看,似乎Nginx配置设置了一个上游django配置,指向gems.sock这是一个Unix套接字文件。

uWSGI服务器似乎是通过端口8001上的http服务的.UWSGI服务器应该通过在Nginx conf中为上游Django指令设置的相同Unix套接字文件gems.sock提供服务。

尝试使用选项--socket gems.sock而不是--http:8001。确保您位于gems.sock所在的当前目录中,或者为该选项提供gems.sock的完整路径