【问题标题】:nginx serving from html instead of gunicornnginx 从 html 服务而不是 gunicorn
【发布时间】:2019-07-05 00:34:04
【问题描述】:

我有一个 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;
    }
}

【问题讨论】:

  • 尝试设置listen 8000并重启nginx,然后在浏览器中访问127.0.0.1:8000。如果它有效,则意味着您有另一台服务器正在侦听端口 80。

标签: django nginx gunicorn


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 2016-02-09
    • 2019-02-16
    • 2019-09-19
    • 1970-01-01
    相关资源
    最近更新 更多