我在 nginx
后面用 gunicorn
托管了我的Django休息框架API服务器 . 当我在请求中使用一个小主体将API发送到 nginx
时,响应就出现了 . 但是,如果有大的有效负载,它将返回200 OK响应 .
但是,当我直接点击 gunicorn
时,它会返回正确的响应 .
如果请求有效负载很大,NGNIX正在搞乱响应 .
我通过 tcpdump
捕获数据包,显示响应包含 MALFORMED PACKET
. 以下是TCP转储:
[Malformed Packet: JSON]
[Expert Info (Error/Malformed): Malformed Packet (Exception occurred)]
[Malformed Packet (Exception occurred)]
[Severity level: Error]
[Group: Malformed]
NGINX配置:
server {
listen 6678 backlog=10000;
client_body_timeout 180s;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120s;
proxy_connect_timeout 120s;
proxy_pass http://localhost:8000;
proxy_redirect default;
}
}
我从未见过NGINX在我身上打得很努力 . 任何帮助赞赏 .
1 回答
如果nginx和gunicorn在同一台服务器上运行,而不是使用环回来让两者相互通信,我相信unix套接字的性能会更高一些 . 我可以't tell if you already doing that from the config snippet. The only other thing I'm从gunicorn部署docs看到这可能是有帮助的是
client_max_body_size 4G;
,根据nginx docs默认为1 MB .