1

I'm setting up an AWS server and I finished the tutorial provided by DigitalOcean, however my server doesn't recognize my static files and displays a page with styles only via CDN (Tailwind)

Nginx Configuration:

server {
    listen 80;
    server_name  xxxxxxxxxxxxx;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static {
        alias  /home/ubuntu/Filmes/static;
   }

    location /media {
        root /home/ubuntu/Filmes;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

}

My project settings.py:

import os

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR / "static")

Structure when running python manage.py collectstatic:

- static
|------ admin
|------ css
|------ images
|------ js
|------ staticfiles.json

Tutorial:https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04

John
  • 23
  • 5
  • You have to reboot system – monim Oct 07 '22 at 00:08
  • Thanks but it was worth the try – John Oct 07 '22 at 01:01
  • Try appending a slash after `location /static` and after `alias /home/ubuntu/Filmes/static` that it looks like: `location /static/ {alias /home/ubuntu/Filmes/static/;}` then restart nginx. `alias` works different than `root` and needs a trailing `/` – hanspeters205 Oct 07 '22 at 04:36
  • I copied exactly as you suggested: `location /static/ {alias /home/ubuntu/Filmes/static/;}` and still nothing – John Oct 07 '22 at 05:00
  • So I went to look in my project directory. And have two parts: static and staticfiles. I tried staticfiles and it worked. I don't know why it created two parts. But thanks for the help! – John Oct 07 '22 at 05:18
  • if you but Debug=False, please check there https://stackoverflow.com/questions/73926690/user-uploaded-images-not-serve-after-debug-false-in-django/73928488#73928488 – Hashem Oct 07 '22 at 10:14
  • Thanks. I'll do it. But it's a server for testing, I'm going to kill the machine after finishing. – John Oct 07 '22 at 16:28

0 Answers0