Sun*_*nib 7 http nginx reverse-proxy request chunked
首先是一些背景:我们有一个嵌入式设备,可以将许多小事件上传到 Web 服务器。分块编码用于发布此信息。每个事件都作为一个单独的块发送,因此网络服务器 (node.js) 可以立即对事件做出反应。所有这一切都像一种魅力。
禁用服务器并在服务器上运行 netcat 显示设备发送的内容:
sudo nc -l 8080
POST /embedded_endpoint/ HTTP/1.1
Host: url.com
User-Agent: spot/33-dirty
Transfer-Encoding: chunked
Accept: text/x-events
Content-Type: text/x-events
Cache-Control: no-cache
120
{"some","json message"}
232
{"other","json event"}
232
{"and a lot more","up to 150 messages per second!"}
0
Run Code Online (Sandbox Code Playgroud)
现在我在我的网络服务器上安装了 nginx(版本 1.6.0)。最后我希望它处理 SSL 并且我想处理加速正常的网络流量。
如果我现在使用此服务器配置启用 nginx:
server {
listen 8080;
location / {
proxy_http_version 1.1;
expires off;
proxy_buffering off;
chunked_transfer_encoding on;
proxy_pass http://localhost:5000;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我收到这个:
sudo nc -l 8080
POST /embedded_endpoint/ HTTP/1.1
Host: localhost:5000
Connection: close
Content-Length: 2415
User-Agent: spot/33-dirty
Accept: text/x-events
Content-Type: text/x-events
Cache-Control: no-cache
{"some","json message"}
{"other","json event"}
{"and a lot more","up to 150 messages per second!"}
Run Code Online (Sandbox Code Playgroud)
问题在于这是缓冲的,现在每 2 秒发送一次请求。所有消息都包含在内并且可以处理。但是现在有延迟......
我可以指示 nginx 直接转发我的块吗?只有这个嵌入式端点才会发生这种情况。我知道当您为所有端点禁用此功能时,在 nginx 中没有太大用处。
如果您可以升级到 Nginx 1.8.x 或 Nginx 1.9.x,您现在可以使用此指令禁用请求缓冲:
proxy_request_buffering off
Run Code Online (Sandbox Code Playgroud)
认为这应该可以解决您的问题。
| 归档时间: |
|
| 查看次数: |
21596 次 |
| 最近记录: |