POCO HttpServer 与 nginx 代理
我最近遇到了用于 c++ 的 POCO 项目,并对它非常感兴趣。它还有一个我想使用的内置 HttpServer。
我按照示例构建了一个简单的 http 服务器,侦听端口 8000。然后我将 nginx 配置为 proxy_pass 所有到端口 8000 的请求。
使用代理,浏览器将内容大小显示为第一个字符,并在尾部添加 0 个字符。例如,我仅使用来自 HttpServer 的“test”字符串进行响应,然后在浏览器端的响应是“4 test 0”。当我直接访问端口 8000 时,响应正确显示,没有任何数字。
因为当我将它与 nginx 代理一起使用时出现问题,所以我认为我的代理设置有问题。我阅读了 nginx 的 代理配置 wiki 页面,但无法得到任何线索为什么会发生这种情况。
我的 nginx 配置如下,
upstream pocotest {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://pocotest;
proxy_set_header X-Real-Ip $remote_addr;
proxy_buffering on;
proxy_pass_request_body on;
proxy_pass_request_headers on;
}
}
I recently came across with POCO project for c++ and pretty interested about it. It has also a builtin HttpServer that I want to play around.
I'm following the examples and built a simple http server listening on port 8000. Then I'm configuring my nginx to proxy_pass all requests to port 8000.
With proxy, browser shows content size as the very first character and adds 0 character to tail. For example I'm only responding with "test" string from HttpServer and then at the browser side the response is "4 test 0". When I directly access to port 8000 response is correctly shown without any numbers.
Because problem occurs when I use it with nginx proxy so I thought there is something wrong about my proxy settings. I read the proxy configuration wiki page of nginx but couldn't get any clue why this is happening.
my nginx conf as follows,
upstream pocotest {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://pocotest;
proxy_set_header X-Real-Ip $remote_addr;
proxy_buffering on;
proxy_pass_request_body on;
proxy_pass_request_headers on;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您返回的是分块编码的响应。 4 是内容为“test”的块的长度。分块消息标记末尾的 0。
最有可能的是,nginx 没有在响应中添加 Transfer-Encoding: chunked 标头。
What you are getting back is chunked encoded response. 4 is the length of the chunk with content "test". The 0 in the end of chunked message marker.
Most likley nginx is not adding Transfer-Encoding: chunked header to the response.