尝试通过nginx / fastcgi使用eventsource进行流式传输

时间:2022-10-27 22:34:20

I am trying to set up an event stream using MVC.NET, Nginx and Fastcgi. The streaming works fine for me using xsp4, but I have not been able to get it to work through Nginx and Fastcgi. My goal is to open an EventSource stream and to downstream data to my website.

我正在尝试使用MVC.NET,Nginx和Fastcgi设置事件流。流式传输对我来说使用xsp4很好,但是我无法通过Nginx和Fastcgi来使用它。我的目标是打开一个EventSource流和下游数据到我的网站。

I have tried adding the 'ngx_http_upstream_keepalive' module - http://wiki.nginx.org/HttpUpstreamKeepaliveModule - which is funny because there is "Note - this This will not work with HTTP upstreams" in the module description. But wait, isn't that the name of the module? Anyways, maybe I'm confused here. I have also tried adding 'proxy_buffering off' to my nginx.conf, which also hasn't helped.

我已经尝试添加'ngx_http_upstream_keepalive'模块 - http://wiki.nginx.org/HttpUpstreamKeepaliveModule - 这很有趣,因为模块描述中有“注意 - 这不适用于HTTP上游”。但等等,是不是模块的名称?无论如何,也许我在这里很困惑。我也尝试将'proxy_buffering off'添加到我的nginx.conf中,这也没有帮助。

I understand this should be fairly easy to do, but I am at a loss. Is there some property I can add to my nginx.conf to make this work? Or is there something to add to the Response in .NET?

我明白这应该是相当容易的,但我不知所措。我可以添加一些属性来添加到我的nginx.conf中吗?或者有什么东西可以添加到.NET中的响应?

Please help me *!

请帮帮我*!

1 个解决方案

#1


6  

Based on what I have read here:

根据我在这里读到的内容:

http://wiki.nginx.org/X-accel

you need to turn off X-Accel-Buffering. Here is some example code:

你需要关闭X-Accel-Buffering。这是一些示例代码:

public ActionResult Stream(string id)
{
    Response.ContentType = "text/event-stream";
    Response.Buffer = false;
    Response.BufferOutput = false;
    Response.Headers["X-Accel-Buffering"] = "no";
    return View();
}

Hopefully the code above fixes your problem.

希望上面的代码能够解决您的问题。

#1


6  

Based on what I have read here:

根据我在这里读到的内容:

http://wiki.nginx.org/X-accel

you need to turn off X-Accel-Buffering. Here is some example code:

你需要关闭X-Accel-Buffering。这是一些示例代码:

public ActionResult Stream(string id)
{
    Response.ContentType = "text/event-stream";
    Response.Buffer = false;
    Response.BufferOutput = false;
    Response.Headers["X-Accel-Buffering"] = "no";
    return View();
}

Hopefully the code above fixes your problem.

希望上面的代码能够解决您的问题。