【问题标题】:How to get nginx to serve django admin css files from different port如何让 nginx 从不同的端口提供 django admin css 文件
【发布时间】:2018-10-07 05:49:18
【问题描述】:

所以我知道有人问过这个问题,但我不确定我的初始设置是否正确。

我正在运行 nginx 来为我的 angular 5 文件提供服务。我让 daphne 为我的频道和 django 代码提供服务。但我不确定如何从 django admin 获取我的静态文件。

nginx 正在监听 80 端口,daphne 在 8080 端口监听。所以要让我的管理员访问http://whatever:8080/admin。管理界面在那里,但它不加载 css 文件。

如何更改我的 nginx 以使其从另一个端口加载静态文件?

这是我的 nginx-conf 的样子

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/whatever;

    index index.html index.htm index.nginx-debian.html;

    server_name localhost;

    access_log /home/ubuntu/.../logs/nginx-access.log;
    error_log  /home/ubuntu/.../logs/nginx-error.log;

    location / {
            try_files $uri $uri/ /index.html;
    }

    location /static/ {
            proxy_pass              http://127.0.0.1:8080;
            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_redirect off;
            alias /home/ubuntu/.../static/;
    }
}

我确定最后一行是不对的,甚至是最后一个位置块。

有什么想法吗?

【问题讨论】:

    标签: django nginx angular5 django-channels daphne


    【解决方案1】:

    所以我不确定这是否是最好的解决方案,但它现在可以工作,安装了 whitenoise 并为我的管理员提供静态文件......

    【讨论】:

      猜你喜欢
      • 2019-02-18
      • 1970-01-01
      • 2015-12-20
      • 2021-12-02
      • 2015-12-15
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      相关资源
      最近更新 更多