简体   繁体   中英

static file are not working in django nginx

I have created one small app, and uploaded to the aws server, i can see everything is working except static folder, my static folder is under the /home/ubuntu/django-bhuriyo/mysite/ this directory, i am using nginx , i have put my code of nginx conf and settings.py, can anyone please look my code and help me to resolve this issue?

django.conf

server {
        listen 80;
        server_name ****.amazonaws.com;

        location /static {
                alias /home/ubuntu/django-bhuriyo/mysite;
        }

        location /  {
                include proxy_params;
                proxy_pass http://unix:/home/ubuntu/django-bhuriyo/app.sock;
        }

}

settings.py

STATIC_URL  = 'static'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

STATIC_ROOT = '/home/ubuntu/django-bhuriyo/mysite'

I see everything fine... are you collecting the files?

python manage.py collectstatic

You need that command for Django to copy over all your static files to the directory specified in the STATIC_ROOT setting. Remember you have to execute that every time you have some change in your static files.

You also have to declare the path of the media.

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

and location for nginx:

  location = /media/ {
        root /path/to/medias;
    }

what is your error traceback?

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