# Static files return 404 codes

**URL:** <https://forum.djangoproject.com/t/static-files-return-404-codes/31970>\
**Category:** Deployment\
**Created:** [June 11, 2024, 12:04pm UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970 "2024-06-11T12:04:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kareem112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kareem112/32/21792_2.png) [@kareem112](https://forum.djangoproject.com/u/kareem112)\
**Post date:** [June 11, 2024, 12:04pm UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970/1 "2024-06-11T12:04:57Z")

</div>

Hi everyone I am relatively new to deploying websites with Django. I’m in the process of deploying my 2nd website on the same server as my 1st website. I’m using this tutorial: [https://www.youtube.com/watch?v=Td3lirXIeRI](https://www.youtube.com/watch?v=Td3lirXIeRI) and they show you how to use the following setup:

- Django
- Gunicorn
- Nginx
- Supervisor

My first website works perfectly fine. The static files are served and the user does not receive any 404’s in the console. I set up my 2nd website the exact same way as my first, and the user receives 404’s for the static files.

Here is some of my code for both sites:

site1.settings.py

```auto
STATIC_URL = 'static/'

MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'media'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'site1/static/')
]

DEBUG = False

ALLOWED_HOSTS = ['www.site1.com', 'site1.com']

CSRF_TRUSTED_ORIGINS = ['https://site1.com']

```

site1-nginx.conf

```auto
upstream site1_app_server {
        server unix:/webapps/site1/run/gunicorn.sock fail_timeout=0;
}

server {
        server_name site1.com www.site1.com;

        access_log /webapps/site1/logs/access.log;

        location /static/ {
                alias /webapps/site1/static/;
        }

        location /media/{
                alias /webapps/site1/media;
        }

        location / {
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                if (!-f $request_filename) {
                        proxy_pass http://site1_app_server;
                }
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.site1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.site1.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = site1.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
        listen 80;
        server_name site1.com;
    return 404; # managed by Certbot
}

```

site2 settings.py

```auto
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'site2/static/')
]
STATIC_ROOT = BASE_DIR / "staticfiles"

DEBUG = False

ALLOWED_HOSTS = ['*']

CSRF_TRUSTED_ORIGINS = ['https://site2.com']

```

site2-ngnix.conf

```auto
pstream site2_app_server {
        server unix:/webapps/site2/run/gunicorn.sock fail_timeout=0;
}

server {
        server_name site2.com www.site2.com;

        access_log /webapps/site2/logs/access.log;
        error_log /webapps/site2/logs/error.log;

        location /static/ {
                autoindex on;
                alias /webapps/site2/static/;
        }

        location /media/{
                alias /webapps/site2/media;
        }
        location / {
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                if (!-f $request_filename) {
                        proxy_pass http://site2_app_server;
                }
        }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.site1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.site1.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = www.site2.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80;
        server_name site2.com www.site2.com;
    return 404; # managed by Certbot
}

```

Let me know if you need more information. Any help would be much appreciated.

Thank you.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 12, 2024, 1:22am UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970/2 "2024-06-12T01:22:13Z")

</div>

Please show the messages in the nginx access and error log files for the site 2 requests having errors.

---

<div class="post-metadata">

**Author:** ![kareem112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kareem112/32/21792_2.png) [@kareem112](https://forum.djangoproject.com/u/kareem112)\
**Post date:** [June 12, 2024, 12:03pm UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970/3 "2024-06-12T12:03:58Z")

</div>

site2 error log

```auto
2024/06/12 12:00:45 [error] 329005#329005: *4945 open() "/webapps/site2/static/css/style.css" failed (2: No such file or directory), client: [IP], server: site2.com, request: "GET /static/css/style.css HTTP/1.1", host: "www.site2.com", referrer: "https://www.site2.com/"

```

site2 access log

```auto
[IP] - - [12/Jun/2024:12:00:45 +0000] "GET /static/css/style.css HTTP/1.1" 404 196 "https://www.site2.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 13, 2024, 2:18am UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970/4 "2024-06-13T02:18:01Z")

</div>

> [@kareem112](#):
>
> `2024/06/12 12:00:45 [error] 329005#329005: *4945 open() "/webapps/site2/static/css/style.css" failed (2: No such file or directory), client: [IP], server: site2.com, request: "GET /static/css/style.css HTTP/1.1", host: "www.site2.com", referrer: "https://www.site2.com/"`

Verify that this file exists as described, and that nginx has access to it - check the permmissions.

---

<div class="post-metadata">

**Author:** ![kareem112](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kareem112/32/21792_2.png) [@kareem112](https://forum.djangoproject.com/u/kareem112)\
**Post date:** [June 14, 2024, 1:54pm UTC](https://forum.djangoproject.com/t/static-files-return-404-codes/31970/5 "2024-06-14T13:54:19Z")

</div>

I found the issue. I had a typo in the site2-nginx.conf file and it was pointing to a folder that did not exist. My static files are visible now. Thanks for the help @KenWhitesell !
