我正在使用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";
}
}
在我的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
我打印出content_len并且它具有正确的值.但是,self.rfile.read()将挂起.最终它会超时并返回“[Errno 32] broken pipe”.
这是我将测试数据发布到服务器的方式:
$curl --data '12345678' localhost:1234
上面的命令也会挂起并最终超时并打印“Closing connection 0”.
我正在做什么明显的错误?
非常感谢!
最佳答案:
Nginx-auth-request-module的代码是annotated at nginx.com.模块总是用空缓冲区替换POST主体.
As the request body is discarded for authentication subrequests, you will
need to set the proxy_pass_request_body directive to off and also set the
Content-Length header to a null string
原因是auth子请求是通过HTTP GET方法发送的,而不是POST.由于GET没有身体,身体被丢弃.现有模块的唯一解决方法是从请求正文中提取所需信息,并将其放入传递给auth服务的HTTP标头中.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。