简体   繁体   English

Django + Nginx + uwsgi不显示静态

[英]Django + nginx + uwsgi doesn't show static

I have a Django project and try to deploy it with nginx and uwsgi (since one week nowadays). 我有一个Django项目,并尝试使用nginx和uwsgi进行部署(因为现在已经有一个星期了)。 I can access to the server but it doesn't show pictures and css. 我可以访问服务器,但是它不显示图片和CSS。 nginx serves static files (for example localhost:8000/static/images/image.png works) but on localhost:8001/ nothing (this page should display an image.png). nginx提供静态文件(例如localhost:8000 / static / images / image.png可用),但在localhost:8001 /上则不提供任何内容(此页面应显示image.png)。

Here's my nginx.conf 这是我的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: 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: wsgi.py:

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

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

I launch uwsgi with: 我用以下方式启动uwsgi:

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

Does anyone have an idea ? 有人有主意吗?

Thanks 谢谢

From the looks of it, it appears the Nginx config is setup with an upstream django config that points to gems.sock which is a Unix socket file. 从它的外观看,似乎Nginx配置已设置为上游django配置,它指向gems.sock(这是一个Unix套接字文件)。

The uWSGI server appears to be serving via http on port 8001. The uWSGI server should be serving via the same Unix socket file gems.sock that was set up for the upstream Django directive in the Nginx conf. uWSGI服务器似乎通过端口8001上的http提供服务。uWSGI服务器应该通过为Nginx conf中的上游Django指令设置的Unix套接字文件gems.sock提供服务。

Try using the option --socket gems.sock instead of --http :8001. 尝试使用--socket gems.sock选项而不是--http:8001。 Make sure you are in the present directory that gems.sock is in or give the option the full path to gems.sock 确保您位于gems.sock所在的当前目录中,或为该选项提供gems.sock的完整路径

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

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