所有
我有一个使用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'
并且,这是来自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"
我为这个问题的模糊性道歉。我已经在相同的硬件上使用相同的库多次设置此服务器,之前没有任何问题。错误令人困惑,我不确定从哪里开始寻找。
提前致谢!
答案 0 :(得分:5)
愚蠢的错误。我的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;
}
}
答案 1 :(得分:3)
仅供参考:我收到同样的错误,并意识到我忘记在user1558914的答案中添加include uwsgi_params;
。
然后它仍然没有在make restart
之后工作,因为我在nginx重启之前有我的uwsgi重启规则,它失败了。一旦我用/etc/init.d/nginx restart
手动重启nginx,KeyError就停止了。