1

I couldn't seem to get routing to work properly. I've also included the collectstatic when i run.

In my settings.py i have the follow code

STATIC_URL = '/static/'
STATIC_ROOT = "/code/static"

in my nginx config file

worker_processes 1;

events {

    worker_connections 1024;

}

http {

    server {
        listen 80;
        server_name example.org;

        access_log /dev/stdout;
        error_log /dev/stdout info;

        location /static/ {
            autoindex on;
            root /code;
        }


        location / {
            proxy_pass http://web:8000;
            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;
        }
    }
}

Error Log

 2017/05/04 13:14:54 [error] 5#5: *1 open() "/code/static/css/bootstrap.min.css" failed (2: No such file or directory),client: 172.18.0.1, server: example.org, request: "GET /static/css/bootstrap.min.css HTTP/1.1", host: "localhost", referrer: "http://localhost/polls/"

Server Directory

root@729dc46f5760:/# cd /code/static
root@729dc46f5760:/code/static# ls -l
total 16
drwxr-xr-x 6 root root 4096 May  4 13:40 admin
drwxr-xr-x 2 root root 4096 May  4 13:40 css
drwxr-xr-x 2 root root 4096 May  4 13:40 fonts
drwxr-xr-x 2 root root 4096 May  4 13:40 scripts
root@729dc46f5760:/code/static#

2 Answers 2

1

Try update your nginx config file at location:static section to this

...
location /static/ {
    autoindex on;
    alias /code/static/;
}
...

FYI deploy django with nginx

Sign up to request clarification or add additional context in comments.

Comments

0

Your STATIC_ROOT is "/code/static" but your nginx configuration maps /static/ to "/code". These should be the same.

1 Comment

can you be more specific about what i need to change?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.