Gunicorn Nginx Django static files

I've been digging through articles and posts about this subject but can't seem to get my images to load. For some reason the CSS on my pages seems to load just fine.

DJANGO
settings.py file

BASE_DIR = Path(__file__).resolve().parent.parent


STATIC_URL = '/static/'

I've tried:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = '/var/www/myname/'

HTML Page
<img src="{% static 'picture.jpg' %}" class="img-fluid">

NGINX
/etc/nginx/sites-enabled/django_project

server {
    listen 80;
    server_name mywebsite.com;

    location /static/ {
        alias /var/www/myname/static/;
    }
}


DIR TREES
/var/www/myname
└── static
    └── admin
        ├── css
        │   ├── styles1.css
        │   └── styles2.css
        ├── images
        │   ├── picture.jpg
        │   └── python.jpg
        └── js
            └── scripts.js


/home/myname/myprojectdir
├── django_project     
│   ├── django_project 
│   │   └── __pycache__
│   ├── etc            
│   ├── index                   
│   │   ├── migrations          
│   │   │   └── __pycache__     
│   │   ├── __pycache__         
│   │   └── templates           
│   │       └── index           
│   │           └── backups     
│   ├── __pycache__             
│   └── static                  
│       ├── admin               
│       │   ├── css             
│       │   │   └── vendor      
│       │   │       └── select2 
│       │   ├── fonts           
│       │   ├── images          
│       │   │   └── gis         
│       │   ├── img             
│       │   │   └── gis         
│       │   └── js              
│       │       ├── admin       
│       │       └── vendor      
│       │           ├── jquery  
│       │           ├── select2 
│       │           │   └── i18n
│       │           └── xregexp 
│       ├── images
│       └── index
│           ├── css
│           ├── images
│           └── js
├── myname_env
│   ├── bin
│   └── lib
│       └── python3.10
│           └── site-packages
└── static
    └── admin
        ├── css
        │   └── vendor
        │       └── select2
        ├── fonts
        ├── img
        │   └── gis
        └── js
            ├── admin
            └── vendor
                ├── jquery
                ├── select2
                │   └── i18n
                └── xregexp


I've tried installing the static files in other directories, etc, to see what works but I'm not having any luck whatsoever. I had the static files in the project but after reading that's not a good practice I put them into var/www. Any and all help on this would be appreciated. Not sure what the deal is.

can you add this into nginx conf and try:

location /images/ {
        alias /var/www/myname/static/images;
    }
Back to Top