Skip to content

Nginx won't load static files. Django opens just fine #194

@timonoj

Description

@timonoj

Hi guys!

I'm trying to setup my nginx for the first time. Somehow...I don't get nginx to load static content. But if I open the 8001 django URL, that one works just fine. I'm sure I must be missing something incredibly obvious, but I'm at my wits end right now, after several hours trying.

So...this is my systemd service file:

[Unit]
Description=Execute the etebase server.

[Service]
WorkingDirectory=/home/localuser/etebase
#ExecStart=/home/localuser/etebase/.venv/bin/uvicorn etebase_server.asgi:application --host 0.0.0.0 --port 8001
ExecStart=/home/localuser/etebase/.venv/bin/uvicorn etebase_server.asgi:application --uds /tmp/etebase_server.sock

[Install]
WantedBy=multi-user.target

this is my etebase-server.ini:

[global]
secret_file = secret.txt
debug = false
;Set the paths where data will be stored at
static_root = /home/localuser/etebase/static
media_root = /home/localuser/etebase/media


[allowed_hosts]
allowed_host1 = test.url
allowed_host2 = *

[database]
engine = django.db.backends.sqlite3
name = db.sqlite3

....and this is the nginx file.


# the upstream component nginx needs to connect to
upstream etebase {
    server unix:///tmp/etebase_server.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name 192.168.0.15 # substitute your machine's IP address or domain name
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static/ {
        alias /home/localuser/etebase/static; # Project's static files
    }

    location / {
        proxy_pass http://etebase;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }
}

Do you guys see whatever I might have missed?

Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions