Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to stream using eventsource through nginx/fastcgi

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.

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.

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?

Please help me StackOverflow!

like image 447
rposky Avatar asked Aug 26 '11 23:08

rposky


1 Answers

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:

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.

like image 112
Joshcodes Avatar answered Nov 04 '22 20:11

Joshcodes