handler before proxy-pass

Maxim Dounin mdounin at mdounin.ru
Thu May 29 12:29:22 UTC 2014


Hello!

On Thu, May 29, 2014 at 03:05:15PM +0300, Donatas Abraitis wrote:

> Hello,
> 
> I want to add a custom 'handler', which would update ngx_os_argv[0] on
> request. It should be like this:
> 
> root     18601  0.0  0.0  62272  3812 ?        Ss   07:00   0:00 nginx:
> master process /opt/nginx/bin/nginx -c /opt/nginx/etc/nginx.conf
> web      18602  0.0  0.0  70372  7904 ?        S    07:00   0:00  \_
> 183.54.68.10 [test.domain.com] GET /ok.php HTTP/1.1??Host
> 
> It works if using only nginx for static content, but if having proxy_pass
> in location directive it doesn't work.

This isn't going to work in any case, as there are multiple 
requests in a single worker process.

> Code snippet is like this:
> 
> {
> ...
>    sprintf(title, "%s [%s] %s", r->connection->addr_text.data,
> r->headers_in.server.data, r->request_line.data);
>    memcpy(ngx_os_argv[0], title, MAXBUF);
>    return NGX_DECLINED;
> }
> 
> Question is, how to solve this problem to update ngx_os_argv[0] if using
> together with proxy_pass? Seems it bypass my 'handler' if using proxy_pass.
> Maybe there is some kind of sequence of loading modules?

>From what you write it looks like you've installed your code as a 
content handler.  You should instead use something like postread 
phase handler, see e.g. realip module for an example.  But, well, 
it's not going to work anyway, see above.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list