错误:上游prematurely关闭的连接,而阅读从上游响应头[uWSGI / Django的/ NGINX] [英] Error: upstream prematurely closed connection while reading response header from upstream [uWSGI/Django/NGINX]

查看:1281
本文介绍了错误:上游prematurely关闭的连接,而阅读从上游响应头[uWSGI / Django的/ NGINX]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前总是得到一个502的查询我的用户在做什么?这通常会返回872行,需要2.07到MySQL中运行。然而,它返回的信息很多。 (每行包含了很多的东西)。任何想法?

运行的Django(tastypie REST API),Nginx的和uWSGI堆栈。

服务器配置与NGINX

 #上游组件的nginx需要连接到
上游Django的{
    服务器UNIX:///srv/www/poka/app/poka/nginx/poka.sock; #一个文件插座
}

服务器#配置
服务器 {
    #端口您的网站将送达
    听443;


    #域名,将服务于
    服务器名XXXX; #替换为您的机器的IP地址或FQDN
    字符集UTF-8;

    #最大上传大小
    client_max_body_size 750M; #调整口味

    #最后,将所有非媒体请求Django的服务器。
    位置 / {
        uwsgi_pass Django的;
        包括/ SRV /网络/ POKA / APP / POKA / nginx的/ uwsgi_params; #在uwsgi_params文件安装
    }
}
 

UWSGI配置

 #过程相关的设置
# 主
主=真
工作进程#最大数量
流程= 2
#插槽(使用完整路径是安全的
插座= /srv/www/poka/app/poka/nginx/poka.sock
#......有相应的权限 - 可能需要
CHMOD插槽= 666
在退出时清除环境
真空=真

pidfile进程= /tmp/project-master.pid#创建一个pidfile进程文件
以超过20秒切腹= 120#重生过程
5000服务请求后,MAX-请求= 5000#重生过程
以进程= /var/log/uwsgi/poka.log#后台进程和放大器;登陆
登录MAXSIZE =千万
#http://uwsgi-docs.readthedocs.org/en/latest/Options.html#post-buffering
后缓冲= 1
logto = /var/log/uwsgi/poka.log#后台进程和放大器;登陆
 

解决方案

这是不太可能是nginx的配置问题。

这是几乎可以肯定的是,后端实际上是崩溃(或只是终止连接),而不是给一个格式错误的响应。即该错误信息是告诉你问题是什么,但你找错了地方,以解决这个问题。

您没有提供足够的信息,从而允许使用找出确切的是什么问题,但如果要我猜:

  

通常会返回872行,需要2.07到MySQL中运行。然而,它返回的信息很多。

这是不是超时的地方或运行内存。

I am currently ALWAYS getting a 502 on a query my users are doing... which usually returns 872 rows and takes 2.07 to run in MySQL. It is however returning a LOT of information. (Each row contains a lot of stuff). Any ideas?

Running the Django (tastypie Rest API), Nginx and uWSGI stack.

Server Config with NGINX

# the upstream component nginx needs to connect to
upstream django {
    server unix:///srv/www/poka/app/poka/nginx/poka.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on
    listen  443;


    # the domain name it will serve for
    server_name xxxx; # substitute your machine's IP address or FQDN
    charset     utf-8;

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

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

UWSGI config

# process-related settings
# master
master          = true
# maximum number of worker processes
processes   = 2
# the socket (use the full path to be safe
socket          = /srv/www/poka/app/poka/nginx/poka.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true

pidfile = /tmp/project-master.pid # create a pidfile
harakiri = 120 # respawn processes taking more than 20 seconds
max-requests = 5000 # respawn processes after serving 5000 requests
daemonize = /var/log/uwsgi/poka.log # background the process & log
log-maxsize = 10000000
#http://uwsgi-docs.readthedocs.org/en/latest/Options.html#post-buffering
post-buffering=1
logto = /var/log/uwsgi/poka.log # background the process & log

解决方案

This is unlikely to be an nginx config issue.

It's almost certainly that the backend is actually crashing (or just terminating the connection) rather than giving a malformed response. i.e. the error message is telling you what the problem is, but you're looking in the wrong place to solve it.

You don't give enough information to allow use to figure out what the exact issue is but if I had to guess:

which usually returns 872 rows and takes 2.07 to run in MySQL. It is however returning a LOT of information.

It's either timing out somewhere or running out of memory.

这篇关于错误:上游prematurely关闭的连接,而阅读从上游响应头[uWSGI / Django的/ NGINX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆