Response with mixed file + generated contents

Evan Miller emmiller at
Thu Sep 6 20:52:54 MSD 2007

Adrian Perez de Castro wrote:
> Hello to all,
> First of all, I will introduce myself: my name is Adrian and I work for
> the Free Software Office of the University of A Coruña (Spain). As part
> of our tasks here, we are maintaining a mirror of several open source
> projects (, also by ftp and rsync), which we are
> planning to migrate from Apache to Nginx.
> I am currently working on a replacement for the autoindex module
> (currently named fancyindex) which outputs XHTML tables instead of a
> big <pre> element. Also, it supports embedding a "readme" file
> (currently using an <iframe>, which is useful to embed full HTML
> documents inside the gerated indexes, but I am planning to add inline
> support as well), and finally I would like to implement configurable
> headers and footers for the listings.
> After a quick read on the server's code, I would like to know a bit more
> about how the output chain gets sent to the client, because I would
> like to do the following when custom header/footer are enabled instead
> of the builtin ones:
>  1. Send custom header: Fill in a ngx_buf_t with the details of the
>     header file.
>  2. Generate XHTML table with file listing, in a memory buffer as
>     autoindex does (and as I am doing right now). Chain it as next
>     buffer of the one created in (1).
>  3. Send custom footer: Fill in a ngx_buf_t with the details of the
>     footer file. Chain it as next buffer of the one created (2).
> Currently, for the buffers created in steps (1) and (3) I am filling
> "buffer->file" with the file info values, setting "buffer->last" to
> the length of the file and "buffer->in_file" to 1.

You probably want to do a subrequest to include #1 and #3 instead. Check 
out the
addition_filter module:

This way the header and footer can be a file on disk or on a remote server.

If you haven't come across it already, you might find my guide to Nginx 
development useful:

When you're finished with it, please be sure to add your module to the 
Nginx wiki:

Good luck!


> Can someone confirm that it is ok and Nginx will open and send the
> file for me? (I will be experimenting myself in the meanwhile, too).
> Also, will Nginx notice I filled in the "buffer->file" member and use
> "sendfile()" if possible? (or any other method which the server will
> consider "optimal").
> Although I am aware my module will not be as fast as the built-in
> autoindex module, I am trying to make it as efficient as possible, and
> I have been reading portions of Nginx code to keep up with it -- and I
> found it very clean and interesting to read, which I think is a Good
> Thing(tm).
> Thank you in advance, and for such a wonderful piece of software!
> P.S. If someone is interested, I can publish the repository with the
> code of module, it is BSD-licensed as Nginx.

More information about the nginx mailing list