Question

My Django Project is not serving static files on Digital Ocean Server

My Project files are in the root directory. The settings.py of my project is



STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS =['/root/templates/colorlib-regform-6']
STATIC_ROOT = '/root/static'
MEDIA_ROOT = '/root/media'

there are folders named static and media for holding static files

gunicorn is also working plus Nginx is also ok. No errors:

/etc/nginx/sites-available/Projectname

server {
    listen 80;
    server_name 104.131.89.148;

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

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

Then I have tried restarting gunicorn and nginx plus

python3 manage.py collectstatic

This also works fine and static files are collected. Everything is working fine, except the server is not serving static files. The project works perfectly in local.

Any help or suggestions regarding this,


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
December 14, 2020
Accepted Answer

Hi @rikeshk012330,

This seems like a long shot but are you sure you are using the proper ownership and permissions. I think the issue might be exactly ownerships. Since Nginx is not using root but another group and user, most probably it’s unable to access your /static folder and server these files.

Try changing this folder and everything inside to be with the user and group of Nginx. You can find this environment setting in Nginx’s config.

Regards, KFSys

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.