Nginx unable to server static and media images

I have a django app on DigitalOcean droplet running using gunicorn and nginx. The site is working but the static files are giveing 404. Below is my ‘/etc/nginx/sites-available/django-project’ file:

server {

        #listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;


        root /usr/share/nginx/html;
        index index.html index.htm;

        #access_log off;

        client_max_body_size 4G;
        #server_name _;

        keepalive_timeout 5;

        location /media  {
           alias /home/django/django_project/django_project/media;

        location /static/ {
            alias /home/django/django_project/django_project/static;

        location / {

                proxy_redirect off;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $http_host;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM N$

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

As long as the path you have listed is correct this should work. I would recommend checking to ensure that the files and directory will allow the www-data user (which nginx is running as) is able to view files in that location. You may need to adjust permissions or ownership (especially if you uploaded them as root or this home directory is not set up to allow access by non-root users other than the django user).