How to serve files with Django and Nginx

Hello I really need help with my static files Can someone give me step by step process on how to serve the static files

        listen 80;

        location /static {
                root /usr/local/var/www/; 

htdocs have all my static files

STATIC_URL = '/static/'

STATIC_ROOT = '/usr/local/var/www/'

I am using a template and dont know how it works


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

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.

Do not forget to configure these files:

/etc/systemd/system/gunicorn.socket /etc/systemd/system/gunicorn.service

very careful with the user sammy, replace with the real user

I dont have to add nothing in my code like {% load static from staticfiles %}


What you have above should work for requests for files in the directory below.


… though it won’t handle requests for anything else, so if a file is located anywhere other than within that directory, NGINX won’t serve it.

If you’re seeing errors, please run:

tail -20 /var/log/nginx/error.log

… and paste the output in a code block.