首页 > 解决方案 > nginx 停止使用 WSL 为 django 应用程序提供静态文件夹

问题描述

我正在使用 WSL 运行 nginx 在“d”分区上为 django 应用程序提供服务,昨天它工作得很好,今天停止正常工作。这是我的 conf 文件:

upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server xxx.xxx.x.xxx:8000; 
}

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

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

# Django static

    location /static {
        alias /mnt/d/backend/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

服务器和域名与设置中允许的主机相同。

STATIC_ROOT = os.path.join(BASE_DIR,"static")]

我不确定我是否指的是静态文件的正确路径。由于它们位于不同的位置,我对同时使用虚拟环境和 wsl 有点困惑。

(venv) root@DESKTOP-XXXXXX:/mnt/d/backend

问题是服务器不加载静态文件。

标签: djangonginxuwsgiwindows-subsystem-for-linux

解决方案


推荐阅读