从HTML而不是gunicorn投放的nginx

时间:2019-07-05 00:34:04

标签: django nginx gunicorn

我有一个遵循以下设置的nginx / gunicorn / django应用程序

https://medium.com/@_christopher/deploying-my-django-app-to-a-real-server-part-ii-f0c277c338f4

当我从浏览器转到主IP(我让Django按以下顺序尝试了这些URL模式:admin / ...)时,它可以工作,但是当我进入/ admin时,我得到了404。Nginx日志如下如下:

2019/07/05 00:30:28 [error] 13600#13600: *1 open() "/usr/share/nginx/html/admin" failed (2: No such file or directory), client: 186.190.207.228, server: 127.0.0.1, request: "GET /admin HTTP/1.1", host: "128.199.62.118"

所以它正在尝试从html /提供文件,而不是提供gunicorn,为什么?

Nginx配置:

server {
    listen 80;    
    server_name 127.0.0.1;
    location = /favicon.ico {access_log off;log_not_found off;} 

    location = /static/ {
        root /home/juan/site;    
    }
    location = /media/ {
        root /home/juan/site;
    }

    location = / {
        include proxy_params;
        proxy_pass http://unix:/home/juan/site/site.sock;
    }
}

1 个答案:

答案 0 :(得分:1)

从所有Location指令(第一个除外)中删除=。这意味着完全匹配,而不是您想要的前缀匹配。

location = /favicon.ico {access_log off;log_not_found off;} 

location /static/ {
    root /home/juan/site;    
}
location /media/ {
    root /home/juan/site;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/home/juan/site/site.sock;
}