Mysql 错误:从上游读取响应头[uWSGI/Django/NGINX]时,上游过早关闭连接
我目前总是得到一个502关于我的用户正在做的查询。。。它通常返回872行,在MySQL中运行需要2.07。然而,它返回了大量信息。(每行包含很多内容)。有什么想法吗 运行Django(tastypierestapi)、Nginx和uWSGI堆栈 使用NGINX配置服务器Mysql 错误:从上游读取响应头[uWSGI/Django/NGINX]时,上游过早关闭连接,mysql,django,nginx,amazon-ec2,uwsgi,Mysql,Django,Nginx,Amazon Ec2,Uwsgi,我目前总是得到一个502关于我的用户正在做的查询。。。它通常返回872行,在MySQL中运行需要2.07。然而,它返回了大量信息。(每行包含很多内容)。有什么想法吗 运行Django(tastypierestapi)、Nginx和uWSGI堆栈 使用NGINX配置服务器 # the upstream component nginx needs to connect to upstream django { server unix:///srv/www/poka/app/poka/ngin
# 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配置
# 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
这不太可能是nginx配置问题 几乎可以肯定的是,后端实际上正在崩溃(或只是终止连接),而不是给出错误的响应。i、 错误消息告诉你问题是什么,但你在错误的地方寻找解决方法 您没有提供足够的信息来让use了解确切的问题是什么,但如果我不得不猜测: 它通常返回872行,在MySQL中运行需要2.07。然而,它返回了大量信息
它要么在某处超时,要么内存不足 在@django位置块中,您可以尝试添加一些代理读取和连接超时属性。e、 g
location @django {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
# proxy header definitions
...
proxy_pass http://django;
}
我也有同样的问题,为我解决的是将我的域名添加到 设置。例如: 同样的问题,我的意思是我甚至无法加载页面,nginx将返回502而不提供任何可能导致应用程序崩溃的页面 nginx日志包含:
Error: upstream prematurely closed connection while reading response header from upstream
有时这可能是一个权威问题。检查项目目录的权限。这可能是uwsgi配置问题,而不是Nginx。我看到你有uwsgi进程=2和harakiri=120,你有没有试着一个接一个地改变它们以及其他字段 我也有同样的问题,但这不是我的NGINX配置,而是我的UWSGI进程在我将json从客户端发布到服务器时导致超时错误。我把进程设为5,我把它改为1,它解决了这个问题。对于我的应用程序,一次只需要运行一个进程 以下是正在工作的UWSGI配置autoboot ini文件,它解决了超时问题,从而解决了502网关问题(上游提前关闭) autoboot.ini
#!/bin/bash
[uwsgi]
socket = /tmp/app.sock
master = true
chmod-socket = 660
module = app.wsgi
chdir = home/app
close-on-exec = true # Allow linux shell via uWSGI
processes = 1
threads = 2
vacuum = true
die-on-term = true
希望有帮助。显而易见的答案是分割数据或增加超时时间。这不起作用吗?我在哪里可以增加超时?增加harakiri也没用。。。我需要在不久的将来实际分割数据。。。但是我现在没有时间…我想2.07秒是秒?日志里有什么吗?直接运行uWSGI HTTP服务器以查看uWSGI或nginx是否阻塞?是的,几秒钟后。。。但问题是872排现在还不算什么。。。在不久的将来它可能会增长到10000。但用户最终需要将这10000行数据以某种方式输入到他的iPad中。我应该开始考虑成批发送数据吗?872行现在算不了什么。。。在不久的将来它可能会增长到10000。但用户最终需要将这10000行数据以某种方式输入到他的iPad中。我应该开始研究成批发送数据吗?不,您应该找到导致后端终止请求的原因。对于内存不足的问题,请向上投票。我认为这在短期内很难实现,内存可能是这样的错误流的一个问题。前3行帮助我解决了502 ws错误
#!/bin/bash
[uwsgi]
socket = /tmp/app.sock
master = true
chmod-socket = 660
module = app.wsgi
chdir = home/app
close-on-exec = true # Allow linux shell via uWSGI
processes = 1
threads = 2
vacuum = true
die-on-term = true