【问题标题】:"(111: Connection refused) while connecting to upstream, client: " | Django, Gunicorn, Nginx - Server Error(500)“(111:连接被拒绝)同时连接到上游,客户端:” | Django、Gunicorn、Nginx - 服务器错误(500)
【发布时间】:2020-04-09 11:19:06
【问题描述】:

我已经部署了我的 django 应用程序,但出现 500 错误。当我输入主页网址“mysite.com”时,它会出现错误并且不会加载,但是当我输入“mysite.com/careers”或“mysite.com/sell”时,它恰好是完全静态页面,它很漂亮。主页和其他具有动态数据的页面不提供。 在阅读了一些相关问题之后,这似乎是一个 Gunicorn 问题。 这里可能是什么问题?以下是 Nginx 的错误日志。

Nginx 错误日志:

2019/12/16 17:30:15 [error] 20605#20605: *1370 connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xx.xx, server: xxx.xxx.xxx.xxx, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "mysite.com"

nginx .conf 文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##
        client_max_body_size 0;
        proxy_max_temp_file_size 0;
        proxy_buffering off;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
...
}

nginx 站点可用文件:

server {
    listen 80;
    server_name xxx.xxx.xxx.xxx mysite.com www.mysite.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/djangoadmin/pyapps/MySite;
    }

    location /media/ {
        root /home/djangoadmin/pyapps/MySite;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

如果您能帮我们解决这个问题,我们将不胜感激。我快到了!

【问题讨论】:

    标签: django nginx gunicorn nginx-reverse-proxy nginx-config


    【解决方案1】:

    我相信你从这个可能的麻烦列表中得到了一些东西:

    1. 您没有运行 gunicorn,因为有任何错误或尚未启动。

    2. 您的 gunicorn 进程正在侦听另一个 unix 套接字路径或 ip 端口。

    3. 你的socket权限不对,nginx因为权限问题无法连接

    【讨论】:

    • 奇怪的是,当手动输入 url 时,站点中的某些页面确实会加载;所有的静态页面。在这种情况下,您的一个理论是否仍然如此?
    • 你说的是静态页面/资源吗?
    • 当我说“静态页面”时,我只是指网站中没有 Django 模板或动态数据的硬编码页面。
    • 页面/资源 url 是什么?
    • 对不起,澄清你的问题?我对此很陌生。在我的问题中,“mysite.com/careers”会起作用,但“mysite.com”不会。
    【解决方案2】:

    我的问题的根源是未能在我的服务器上运行新的迁移。 所有受影响的页面都是显示与这些模型相关联的数据的页面,或者它们是外键的页面。 在找到答案时,我犯了一个严重的生产罪,就是短暂地打开 Debug:On。希望编程大神们见谅。多谢你们。

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 2017-02-09
      • 2018-04-07
      • 2016-10-06
      • 1970-01-01
      • 2014-02-26
      相关资源
      最近更新 更多