By roth84
I posted here already what the problem is but didn’t get an answer: https://stackoverflow.com/questions/46039302/django-on-nginx-uwsgi-static-files-dont-show
Basically there must be a mistake somewhere so that I cannot see the static files anywhere in the frontend even if “collectstatic” worked and I see the files in the terminal. I followed pretty much the digital ocean tutorial.
What can I do?
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!
Hi there,
In case taht anyone comes across this in the future, I could suggest following the steps from this tutorial here:
Mainly the ‘Adjusting the Project Settings’ step which goes over the static files configuration. As well as the ‘Configure Nginx to Proxy Pass’, so you could make sure that the Nginx configuration is also correct.
Best,
Bobby
If your Django project on Nginx + uWSGI is not serving static files correctly, despite collectstatic successfully collecting them, the issue is most likely related to Nginx’s configuration, file permissions, or how static files are referenced in your project. Here’s a systematic approach to resolving the problem:
After running python manage.py collectstatic, verify the files are in the correct directory specified by STATIC_ROOT in your settings.py. For example:
STATIC_ROOT = "/var/www/html/static/"
STATIC_URL = "/static/"
Check the directory:
ls /var/www/html/static/
Ensure your Nginx configuration properly points to the STATIC_ROOT directory. Open your Nginx configuration file (e.g., /etc/nginx/sites-available/your_project) and confirm the following:
server {
listen 80;
server_name yourdomain.com;
location /static/ {
alias /var/www/html/static/;
}
location /media/ {
alias /var/www/html/media/;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/path/to/your_project/your_project.sock;
}
}
/var/www/html/static/ with your actual STATIC_ROOT directory.sudo systemctl restart nginx
Ensure Nginx has permission to read the static files directory. Check the ownership and permissions:
sudo chown -R www-data:www-data /var/www/html/static/
sudo chmod -R 755 /var/www/html/static/
http://yourdomain.com/static/css/style.css.Check the Nginx error logs for clues:
sudo tail -f /var/log/nginx/error.log
Look for:
Check your templates to ensure static files are referenced correctly using Django’s {% static %} template tag. For example:
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
If {% static %} is not resolving correctly:
django.contrib.staticfiles is in your INSTALLED_APPS.settings.py:from django.templatetags.static import static
location /static/ block is misconfigured.alias path to match your STATIC_ROOT.www-data) cannot access files.sudo chown -R www-data:www-data /var/www/html/static/
sudo chmod -R 755 /var/www/html/static/
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.