使用Gunicorn在Google App Engine灵活的环境中configurationnginx

我正在开发一个Django应用程序,到现在为止我已经将它部署到App Engine标准环境,但是随后我开始使用Google Cloud Vision Python库,并由于一些限制,我切换到灵活环境。

我的代码在我的本地机器上用python manage.py runserver ,但是当我将它部署到App Engine时,我得到了以下内容

 <html> <head> <title>502 Bad Gateway</title> </head> <body bgcolor="white"> <center> <h1>502 Bad Gateway</h1> </center> <hr> <center>nginx</center> </body> </html> 

当我研究这个问题的时候,我发现我需要改变这里所说的nginx设置。

要应用的Nginx设置

 # Tune nginx keepalives to work with the GCP HTTP(S) Load Balancer: keepalive_timeout 650; keepalive_requests 10000; 

但我无法find办法做到这一点。 我也是后端开发的新手,所以我没有太多的经验。

这是我的app.yaml文件

 runtime: python api_version: 1 threadsafe: yes env: flex entrypoint: gunicorn -b :$PORT app.wsgi runtime_config: python_version: 3 handlers: - url: /static static_dir: static - url: .* script: app.wsgi.application builtins: - django_wsgi: on 

我尝试设置entrypoint以下,但它没有工作。

 entrypoint: gunicorn --keep-alive 650 -b :$PORT app.wsgi 

编辑1:此错误只发生POST请求。

编辑2:这是与http请求的错误日志:

 { insertId: "1c0for6fm6z812" jsonPayload: { trace: "$traceId" latencySeconds: "30.529" time: null } httpRequest: { requestMethod: "POST" requestUrl: "/users/register/" status: 502 responseSize: "568" userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" remoteIp: "130.211.3.116" referer: "-" } resource: { type: "gae_app" labels: { project_id: "cuz-api" version_id: "20170504t110352" module_id: "default" } } timestamp: "2017-05-04T08:30:14.560885079Z" labels: { compute.googleapis.com/resource_name: "68f73c569efa" compute.googleapis.com/resource_id: "8300604998554181598" compute.googleapis.com/zone: "us-central1-b" appengine.googleapis.com/trace_id: "7835424c5d67f87f56649adf26e71250" } logName: "projects/cuz-api/logs/appengine.googleapis.com%2Fnginx.request" } 

这是https请求的错误日志:

 { insertId: "95tl7qfm6m4zy" jsonPayload: { time: null trace: "$traceId" latencySeconds: "30.028" } httpRequest: { requestMethod: "POST" requestUrl: "/users/register/" status: 502 responseSize: "568" userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" remoteIp: "130.211.3.237" referer: "-" } resource: { type: "gae_app" labels: { version_id: "20170504t110352" module_id: "default" project_id: "cuz-api" } } timestamp: "2017-05-04T08:26:38.540802339Z" labels: { compute.googleapis.com/zone: "us-central1-b" appengine.googleapis.com/trace_id: "3eab23e9502e250d9f00dd5bc7eb465e" compute.googleapis.com/resource_name: "68f73c569efa" compute.googleapis.com/resource_id: "8300604998554181598" } logName: "projects/cuz-api/logs/appengine.googleapis.com%2Fnginx.request" } 

我相信Nginx并没有真正的需要。 您基于自己的链接与HTTP负载平衡器有关,而不是App Engine Flexible。

在App Engine上灵活使用Django应用程序的例子可以在这里find。

看来你的应用在本地testing机器上运行不好。 如果这样做,通过遵循“从标准环境向灵活环境迁移服务”在线指南 ,将它从标准环境应用程序迁移到柔性变得容易。