using uninitialized "pat" variable while logging request
Valentin V. Bartenev
vbart at nginx.com
Sat Nov 16 00:07:19 UTC 2013
On Saturday 16 November 2013 02:24:43 Toni Mueller wrote:
> Hi,
>
> to debug my locations, I have a variable in my configuration that I
> reference during logging. The log format, included from nginx.conf:
>
> log_format mylogformat '$remote_addr - $remote_user [$time_local] $request
> ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent"
> domain: $host branch: $pat';
>
>
> Unfortunately, I cannot set the variable $pat already in nginx.conf,
> but in my virtual server configuration, I set it like this:
>
> server {
> listen 1.2.3.4:80 default_server;
> server_name www.example.com;
>
> charset utf-8;
> set $pat "-";
>
> # rest of configuration here, eg.:
>
> location = / {
> set $pat "homepage";
> # do something special
> }
>
> # more stuff...
> }
>
>
> So far, my understanding is that the variable $pat should be _always_
> defined, right? Well... I find this in the error log:
[..]
The "set" directive isn't something essential, and actually it is just a
directive from the rewrite module.
See here how it works:
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
It is evaluated on the rewrite phase of request processing. Thus, if
the request is finalized before this phase, then your variable is left
uninitialized.
To debug your locations and for better understanding what is going on,
you can use nginx debug log: http://nginx.org/en/docs/debugging_log.html
wbr, Valentin V. Bartenev
More information about the nginx
mailing list