about the Guide to Nginx Module Development

Evan Miller emmiller at gmail.com
Mon Aug 20 11:32:17 MSD 2007

Manlio Perillo wrote:
> Hi again.
> I have decided to write mod_wsgi by myself, and I have fuond the Evan 
> Miller's guide very helful.

Glad it was useful. I'll try to keep updating it with more info, but in 
the meantime I thought I'd try to answer your specific questions (below).

> However I think that some important documentation is missing:
> 1) The overall architecture of nginx
> 2) nginx memory handling

Nginx has a pool of memory associated with each request (r->pool), which 
is reclaimed at the end of the request. You can malloc memory with 
ngx_palloc(r->pool, BYTES). I'm not sure whether you can free memory 
allocated in this way manually.

> 3) how to read data from the request payload

I'm not sure, actually; but check out 

> 4) how to read and generate arbitrary headers
>    There is an headers attribute in the request struct, what is its
>    content?

I read headers by looking for the variable names that are set (e.g. 
"upstream_http_x_my_header"). The ngx_http_variable_unknown_header() 
function comes in handy.

To set a header, I think you'd use functions in the Headers module, 
something like (making it up here):

ngx_http_headers_conf_t *hcf = ngx_http_get_module_loc_conf(r, 

ngx_http_header_val_t *h = ngx_array_push(hcf->headers);

if (h == NULL) { return NGX_ERROR; }

h->value.hash = 1;
h->value.key = ngx_string("X-My-Header");
h->value.value = ngx_string("Some value");


> 5) More about chain links.
>    When sending the response body, we have two choices
>    (but I'm not sure):
>    - write the entire chain links and then pass it to the output filter
>      (so we buffer the entire response)
>    - create a partial response, create a buffer and call the output
>      filter, then create a new partial response, create a new buffer and
>      call the outputfilter, and so on.

I believe that's correct.

When I research these issues more I'll add them to the guide.

Good luck with mod_wsgi! I know it's a module a lot of people would find 


> Thanks and regards  Manlio Perillo

More information about the nginx mailing list