django / admin未找到

时间:2017-11-01 01:35:27

标签: nginx gunicorn

我尝试设置 Nginx + Gunicorn ,当我通过我的网址时, Nginx 会将请求重定向到我的应用并通过itsels处理静态资源({{1文件夹)。在我的Nginx域配置下面:

static

Gunicorn守护进程

server {
        listen 80;
        server_name asknow.local www.asknow.local;

        root /home/ghostman/Projects/asknow/asknow;

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /static/ {
                root /home/ghostman/Projects/asknow/asknow;
        }
        location = / {
                include proxy_params;
                proxy_pass http://unix:/home/ghostman/Projects/asknow/asknow/asknow.sock;
        }
}

我需要 Nginx 的问题仅针对[Unit] Description=gunicorn daemon After=network.target [Service] User=ghostman Group=www-data WorkingDirectory=/home/ghostman/Projects/asknow/asknow ExecStart=/home/ghostman/Projects/asknow/env/bin/gunicorn --access-logfile /home/ghostman/Projects/asknow/env/log/gunicorn.log --error-logfile /home/ghostman/Projects/asknow/env/log/gunicorn-error.log --workers 3 --bind unix:/home/ghostman/Projects/asknow/asknow/asknow.sock asknow.wsgi:application [Install] WantedBy=multi-user.target 处理请求(static),但它也会尝试处理其他网址。因此,当我转到www.asknow.local/static时, Nginx 会尝试按路径(www.asknow.local/admin)查找资源。但是如果我去my_project/admin Nginx代理请求Gunicorn。 Gunicorn错误日志为空,因此在Nginx端失败。

Nginx日志

www.asknow.local

如何解决?

1 个答案:

答案 0 :(得分:1)

您的问题是使用=,即用于绝对位置。你不想要那个(仅限于favicon.ico)

server {
        listen 80;
        server_name asknow.local www.asknow.local;

        root /home/ghostman/Projects/asknow/asknow;

        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
                root /home/ghostman/Projects/asknow/asknow;
        }
        location / {
                include proxy_params;
                proxy_pass http://unix:/home/ghostman/Projects/asknow/asknow/asknow.sock;
        }
}