The "echo" nginx module: A small step towards Nginx config file scripting

agentzh agentzh at
Sat Oct 24 19:24:51 MSD 2009

Hi, folks!

I've just finished my first run of "echo" module hacking by the v0.15
release. The documentation is on the Nginx wiki site:

I'm not going to repeat everything in the wiki page but only quoting
the "Description" section (please allow me to do that ;)):

    This module provides various utilities that help testing and debugging
    of other modules by trivially emulating different kinds of faked
    subrequest locations.

    People will also find it useful in real-world applications that need to

    1.  serve static contents directly from memory (loading from the Nginx
        config file).

    2.  wrap the upstream response with custom header and footer (kinda like
        the addition module but with contents read directly from the config
        file and Nginx variables).

    3.  merge contents of various "Nginx locations" (i.e., subrequests)
        together in a single main request (using echo_location and its

    This is a special dual-role module that can *lazily* serve as a content
    handler or register itself as an output filter only upon demand. By
    default, this module does not do anything at all.

    Use of any of this module's directives (no matter content handler
    directives or filter directives) will force the chunked encoding to be
    used for the HTTP response due to the streaming nature of this module.

    Technially, this module has also demonstrated the following techniques
    that might be helpful for module writers:

    1.  Issue parallel subreqeusts directly from content handler.

    2.  Issue chained subrequests directly from content handler, by passing
        contination along the subrequest chain.

    3.  Interact with the Nginx event model directly from content handler
        using custom events and timers, and resume the content handler back
        if necessary.

    4.  Dual-role module that can (lazily) serve as a content handler or an
        output filter or both.

    5.  Nginx config file variable creation and interpolation.

    6.  Streaming output control using output_chain, flush and its friends.

    7.  Read client request body from the content handler, and returns back
        (asynchronously) to the content handler after completion.

Hopefully you'll find it funny and useful.


More information about the nginx mailing list