0

We have our Django 1.9.6 application running in a Docker container. The docker container has nginx configured to serve the static files.

We link to /admin and it will take us to the /admin pages but when we click a link it takes us to /usr/src/app/admin/api/module/

I can tell you Django is running from the directory /usr/src/app.

We tried adding FORCE_SCRIPT_NAME='' to the settings and this has not helped.

The Django app is running via Daphne (as we are using Channels)

Here is our nginx config:

server {
    listen      80 default_server;

    charset     utf-8;

    # max upload size
    client_max_body_size 4G;   

    # Django media
    location /media  {
        alias /usr/src/app/media;  
    }

    location /static {
        alias /usr/src/app/static-collect; - amend as required
    }

    location / {
        proxy_pass http://0.0.0.0:8000;
        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;
    }
}`
Scott Warren
  • 1,581
  • 1
  • 17
  • 30

1 Answers1

0

The problem was not nginx or any of it's configuration it was how we started daphne

We had daphne --root-path=/usr/src/app -b 0.0.0.0 -p 8000 config.asgi:channel_layer -v2

In our script to start daphne. One we removed the --root-path=/usr/src/app it all works as expected.

ie daphne -b 0.0.0.0 -p 8000 config.asgi:channel_layer -v2

Scott Warren
  • 1,581
  • 1
  • 17
  • 30