Using sendfile in module

Maxim Dounin mdounin at
Thu May 6 13:30:30 MSD 2010


On Wed, May 05, 2010 at 06:51:15PM -0700, Kent Karlsson wrote:

> I'm considering porting a slow cgi to a module for nginx that 
> provides a custom url scheme to access parts of big files and 
> would like to use sendfile to avoid copying all the data to 
> userspace and back again. I looked at X-Accel-Redirect, but it 
> seems to require that I send the entire file, which won't work 
> for me.

X-Accel-Redirect require URI, it's up to other modules to provide 
entire file or parts of a file as a response to the URI in 
question.  E.g. you may combine X-Accel-Redirect with bytes filter 
to obtain parts of files, see here:

> I need to understand if it is possible first, so if someone can 
> tell me if it is and maybe give me some code or links to read, 
> that would be much appreciated.

Just provide correct in-file buffer, nginx will take care of it 
according to OS capabilities and/or config settings.

See ngx_http_flv_module.c for an example of sending parts of a 
file from content handler module.

Maxim Dounin

More information about the nginx-devel mailing list