简体   繁体   中英

django digitalocean deploy cannot serve static files

I try to deploy my app on digitalocean, when i configure the ngnix server, everything works except all the css and js file are not being served. I have done collectstatic, and my /etc/nginx/sites-available looks like this

server {
    listen 80;
    server_name my ip;

    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {
        root /home/djangodeploy/portfolio-blog;
    }

     location /media/ {
        root /home/djangodeploy/portfolio-blog;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/djangodeploy/portfolio-blog/mysite.sock;
    }
}

and my file structure looks like this

在此处输入图片说明

settings.py

STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'mysite/static') ]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

Why don't you try:

    location /static/ {
        root /home/djangodeploy/portfolio-blog/static;
    }

     location /media/ {
        root /home/djangodeploy/portfolio-blog/media;
    }

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