我正在使用Nginx(版本1.9.9)作为我的后端服务器的反向代理.它需要根据POST请求的内容执行身份验证/授权.我在auth_request处理程序中读取POST请求正文时遇到问题.这就是我得到的.
Nginx配置(相关部分):
server {
location / {
auth_request /auth-proxy;
proxy_pass http://backend/;
}
location = /auth-proxy {
internal;
proxy_pass http://auth-server/;
proxy_pass_request_body on;
proxy_no_cache "1";
}
}
Run Code Online (Sandbox Code Playgroud)
在我的auth-server代码(Python 2.7)中,我尝试读取请求体,如下所示:
class AuthHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def get_request_body(self):
content_len = int(self.headers.getheader('content-length', 0))
content = self.rfile.read(content_len)
return content
Run Code Online (Sandbox Code Playgroud)
我打印出content_len并且它具有正确的值.但是,self.rfile.read()将挂起.最终它会超时并返回"[Errno 32] Broken pipe".
这是我将测试数据发布到服务器的方式:
$ curl --data '12345678' localhost:1234
Run Code Online (Sandbox Code Playgroud)
上面的命令也会挂起并最终超时并打印"Closing connection 0".
我正在做什么明显的错误?
非常感谢!