Problem with Static files in Django project deploy on Digitalocean

Asked

Viewed 109 times

0

I deployed a project Python and Django in the Digitalocean, but I’m having trouble with static files

Inside my project, in the folder static when typing the command pwd to see the full file path, I have the following.

/root/getcode/notafiscal/getcode/static

In settings.py I have:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(APP_ROOT, 'static')

and within /etc/nginx/sites-available/getcode I have the following:

server {
    listen 80;
    server_name meu_endereco_ip;

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

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

However, when accessing the IP address, my site is all disfigured, as if it had not "read" the folder static.

Note. I did all the installation of the application Django in an MV virtualenv.

In setting.py when trading STATIC_ROOT for

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

and reproduce by python manage.py runserver 0.0.0.0:8000, the site appears perfectly configured when accessing the browser meu_ip:8000

Therefore, I believe the error is in some configuration of the nginx. How to solve?

  • Rafael, did check if the folder static contains any files? You even ran the command python manage.py collectstatic on the server?

  • Yes for both questions. When I start the program with the command python manage.py runserver it works on the door :8000. I believe there’s some problem with the configuration of nginx

  • The Static module only serves files when DEBUG=True, when in production should be configured for Nginx or Apache to serve the folder static

  • I set up the folder static to the nginx as described in the question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.