将JSON从Nginx传递到Gunicorn

2024-03-28 21:22:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用nginx作为使用gunicorn的Django应用程序的代理服务器。Django应用程序绑定到http://127.0.0.1:8000。下面是我在etc/nginx/sites enabled/parkitbackend中的nginx设置:

server {

    server_name AA.BB.CC.DD;

    access_log off;

    location /static/ {
        autoindex on;
        alias /home/zihe/parkitbackend/parkitbackend/common-static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8000;
    }
}

我正在使用python请求模块:

^{pr2}$

将JSON对象发布到我的名为dashboard的django应用程序中,我在dashboard中有一个函数/视图.py在JSON中调用对象。在

我没有收到运行JSON发布脚本的任何错误。然而,Nginx似乎无法将请求传递给gunicorn binded,地址为127.0.0.1:8000。我应该怎么做才能使用Nginx将JSON传递到django应用程序?谢谢您!在


附加说明: 我确信JSON发布代码和django应用程序可以正常工作,因为我通过将django应用程序绑定到http://AA.BB.CC.DD:8000进行了测试,并在python中运行了以下代码:

requests.post("http://AA.BB.CC.DD:8000/dashboard/checkin/", data=unicode(json.dumps(payload), "utf8"))

我的django应用程序如期收到了JSON。在


Tags: djangojson应用程序httpservernginxlocationdd
1条回答
网友
1楼 · 发布于 2024-03-28 21:22:09

我检查了错误.log位于/var/log/nginx/。结果是我发送的JSON太大了,并给出了以下错误:

[error] 3450#0: *9 client intended to send too large body: 1243811 bytes, client: 127.0.0.1, server: _, request: "POST /dashboard/checkin/ HTTP/1.1", host: "127.0.0.1"

读完这个链接后:http://gunicorn-docs.readthedocs.org/en/19.3/deploy.html#nginx-configuration

我缩小了JSON的大小并修改了etc/nginx/sites enabled/parkitbackend如下:

^{pr2}$

并在/etc/nginx中替换了这条线/nginx.conf公司公司名称:

include /etc/nginx/sites-enabled/*;

有了这个:

include /etc/nginx/sites-enabled/parkitbackend;

问题就解决了。在

相关问题 更多 >