gpt4 book ai didi

django - nginx + Gunicorn 抛出截断的响应正文

转载 作者:行者123 更新时间:2023-12-02 03:36:08 25 4
gpt4 key购买 nike

我通过某个url请求一些json数据,有时工作正常,有时则不行...我在这里查看了另一个相关提示,但似乎建议不要通过中间件更改内容长度...我的json数据不完整如下图所示:

enter image description here

我的应用程序 nginx 配置:

server {
listen 80;
server_name myapp.com;

access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log;

location / {
client_max_body_size 400M;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8888;
}
}

gunicorn脚本:

#!/bin/bash
set -e
DJANGODIR=/home/ubuntu/apps/myapp

LOGFILE=/var/log/gunicorn/myapp.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=3
# user/group to run as
USER=ubuntu
GROUP=ubuntu
cd /home/ubuntu/apps/myapp
source /home/ubuntu/.venv/myapp/bin/activate

export PYTHONPATH=$DJANGODIR:$PYTHONPATH

export NEW_RELIC_CONFIG_FILE=/home/ubuntu/newrelic/newrelic.ini

test -d $LOGDIR || mkdir -p $LOGDIR
exec /usr/local/bin/newrelic-admin run-program /home/ubuntu/.venv/myapp/bin/gunicorn_django -w $NUM_WORKERS \
--user=$USER --group=$GROUP --log-level=debug \
--log-file=$LOGFILE -b 127.0.0.1:8888 2>>$LOGFILE

最佳答案

嗯...我发现了一个相关问题here ,我将 proxy_buffering off; 添加到配置文件中,这解决了我的情况的问题。

文件如下:

server {
listen 80;
server_name myapp.com;

access_log /var/log/nginx/myapp_access.log;
error_log /var/log/nginx/myapp_error.log;

location / {
client_max_body_size 400M;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8888;
proxy_buffering off;
}
}

关于django - nginx + Gunicorn 抛出截断的响应正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28732103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com