0

我们的 Django 1.9.6 应用程序在 Docker 容器中运行。docker 容器配置了 nginx 来提供静态文件。

我们链接到 /admin,它会将我们带到 /admin 页面,但是当我们单击链接时,它会将我们带到/usr/src/app /admin/api/module/

我可以告诉你 Django 正在从目录 /usr/src/app 运行。

我们尝试添加FORCE_SCRIPT_NAME=''设置,但没有帮助。

Django 应用程序通过 Daphne 运行(因为我们使用的是 Channels)

这是我们的 nginx 配置:

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;
    }
}`
4

1 回答 1

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

于 2017-11-24T04:45:44.567 回答