到特定端点的GET请求导致Python Flask服务器崩溃:

use*_*914 2 python nginx flask uwsgi

所有,

我有一个使用Flask构建的具有两个端点的API。我正在使用nginx / uwsgi组合来提供服务,每当我向端点之一发送GET请求时,我都会收到一个奇怪的错误。另一个端点工作正常。

这是来自get请求的uwsgi日志的输出

File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1646, in request_context
    return RequestContext(self, environ)
File "/usr/local/lib/python2.7/dist-packages/flask/ctx.py", line 166, in __init__
    self.url_adapter = app.create_url_adapter(self.request)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in create_url_adapter
    server_name=self.config['SERVER_NAME'])
File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1196, in bind_to_environ
    environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
KeyError: 'REQUEST_METHOD'
Run Code Online (Sandbox Code Playgroud)

并且,这是来自get请求的nginx错误日志的输出

2013/12/26 15:22:16 [error] 833#0: *9 upstream prematurely closed connection while reading response header from upstream, 
client: 71.71.53.31, server: scholarly, 
request: "GET /citelet/ HTTP/1.1", 
upstream: "uwsgi://unix:///tmp/citelet.sock:", 
host: "162.243.219.38"
Run Code Online (Sandbox Code Playgroud)

对于这个问题的含糊之处,我深表歉意。我已经在相同的硬件,相同的库上多次设置了该服务器,并且之前没有任何问题。错误令人困惑,我不确定从哪里开始寻找。

提前致谢!

use*_*914 6

愚蠢的错误。我的nginx配置出现错误。它指向一个不存在的套接字。

server {
    listen   80;
          server_name scholarly;
      # crowdscholar endpoint
        location /crowdscholar {
            uwsgi_pass unix:///tmp/crowdscholar.sock;
        include uwsgi_params;
        # strip path before handing it to app
        uwsgi_param SCRIPT_NAME /crowdscholar;
        uwsgi_modifier1 30;
    }
    # citelet endpoint
        location /citelet {
            uwsgi_pass unix:///tmp/citelet.sock;
        include uwsgi_params;
        # strip path before handing it to app
        uwsgi_param SCRIPT_NAME /citelet;
        uwsgi_modifier1 30;
    }
}
Run Code Online (Sandbox Code Playgroud)


jco*_*ctx 5

仅供参考:我遇到了同样的错误,并意识到我忘记include uwsgi_params;user1558914的答案中添加。

然后它仍然无法正常工作,make restart因为我的 uwsgi 重新启动规则在 nginx 重新启动之前失败了。一旦我用 手动重新启动 nginx /etc/init.d/nginx restart,KeyError 就停止了。