sendfile() 在向上游 nginx 502 发送请求时失败(32:管道损坏) [英] sendfile() failed (32: Broken pipe) while sending request to upstream nginx 502
问题描述
我正在运行 Django、uwsgi、ngix 服务器.我的服务器适用于较小尺寸的 GET、POST 请求.但是在POST大尺寸的请求时,nginx返回502:nginx error.log 是:
I am running Django, uwsgi, ngix server. My server works fine for GET, POST requests of smaller size. But when POSTing requests of large size, nginx returns 502: nginx error.log is:
2016/03/01 13:52:19 [error] 29837#0: *1482 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 175.110.112.36, server: server-ip, request: "POST /me/amptemp/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "servername"
因此,为了找出真正的问题所在,我在不同的端口上运行了 uwsgi,并检查了同一请求是否发生了任何错误.但是请求成功了.因此,问题出在 nginx 或 unix 套接字配置上.Ngin-x 配置:
So, in order to find where the real problem is, I ran uwsgi on a different port and checked if any error occurs with the same request. But the request was successful. So, the problem is with nginx or unix socket configuration. Ngin-x configuration:
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/uwsgi.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 52.25.29.179; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/usman/Projects/trequant/trequant-python/trequant/media; # your Django project's media files - amend as required
}
location /static {
alias /home/usman/Projects/trequant/trequant-python/trequant/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
######## proxy_pass http://127.0.0.1:8000;
######## proxy_set_header Host $host;
######## proxy_set_header X-Real-IP $remote_addr;
######## proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_pass django;
uwsgi_read_timeout 600s;
uwsgi_send_timeout 600s;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
那么,知道我做错了什么吗?提前致谢.
So, any idea what I am doing wrong? Thank you in advance.
推荐答案
另一个解决方法是使用 TCP 套接字而不是 conf 文件中的 unix 套接字:
Another fix is to use a TCP socket instead of a unix socket in your conf files:
在 uwsgi.ini 中,在
[uwsgi]
部分使用类似socket = 127.0.0.1:8000
的东西,而不是:
In uwsgi.ini, use something like
socket = 127.0.0.1:8000
in the[uwsgi]
section instead of:
socket =/tmp/uwsgi.sockchown-socket = nginx:nginxchmod-socket = 664
在你的 nginx.conf 文件中(顺便说一句,在 Ubuntu 中,我指的是/etc/nginx/conf.d/nginx.conf,而不是简单地在 /etc/nginx/
) 使用 uwsgi_pass 127.0.0.1:8000;
而不是 include uwsgi_params;
In your nginx.conf file (btw in Ubuntu, I'm referring to /etc/nginx/conf.d/nginx.conf, NOT the one simply in /etc/nginx/
) use uwsgi_pass 127.0.0.1:8000;
instead of include uwsgi_params;
我已将此作为单独的答案发布,因为任何一个答案都可能有效,而且我很想知道哪个答案对其他人的帮助最大.
I've posted this as a separate answer because either answer may work, and I'm interested to see which answer helps others the most.
这篇关于sendfile() 在向上游 nginx 502 发送请求时失败(32:管道损坏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!