Welcome! Log In Create A New Profile


Adding cachekey to log_format directive

November 13, 2012 12:55AM
Good morning,

I'm trying to add the generated cache key of a proxied request to a log_format directive. From what I can tell, this variable is not normally available when logging requests so I've to modify the proxy module in ngx_http_proxy_module.c.

So far I've added "cachekey" to the typedef struct: ngx_http_proxy_vars_t so that ngx_http_proxy_set_var can set it.

I've added the declaration:

static ngx_int_t ngx_http_proxy_cachekey_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); and in the corresponding function (which is basically a copy of ngx_http_proxy_host_variable), I do:

v->len = ctx->vars.cachekey.len;
v->data = ctx->vars.cachekey.data;

I've also added:

{ ngx_string("proxy_cachekey"), NULL, ngx_http_proxy_cachekey_variable, 0,

to ngx_http_proxy_vars[] so that proxy_cachekey is available for use in the log_format directive.

Finally in; ngx_http_proxy_set_var(ngx_url_t *u, ngx_http_proxy_vars_t *v) I'm guessing I've to set the key somewhere here:

v->cachekey.len = ??;
v->cachekey.data = ??;

The question I have is, how do I get the generated cache key in the v.cachekey.data field? If I populate these variables with arbitrary data I can see its being logged correctly so am confident I'm in the right place.

Any suggestion would be appreciated,


- WS
Subject Author Posted

Adding cachekey to log_format directive

Wouter van der Schagt November 13, 2012 12:55AM

Re: Adding cachekey to log_format directive

gmccullough November 16, 2012 12:23PM

Re: Adding cachekey to log_format directive

Wouter van der Schagt November 23, 2012 11:58AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 98
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready