简体   繁体   中英

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). I can access to the server but it doesn't show pictures and 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).

Here's my 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()

I launch uwsgi with:

    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.

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.

Try using the option --socket gems.sock instead of --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

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