Forum: NGINX using uninitialized "pat" variable while logging request

A8cae7780631b0e946f4826cd06128a6?d=identicon&s=25 Toni Mueller (Guest)
on 2013-11-15 23:25
(Received via mailing list)
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:

[warn] 11092#0: *15719589 using uninitialized "pat" variable while
logging request, client: 4.3.2.1, server: www.example.com


For a lot of requests, the value of the variable does appear in the log
file, but for a good proportion, it doesn't. I would like to have this
variable always set properly. Can it be a timing question? I get
between ~5 and below 100 requests per second. The machine doesn't look
anywhere near loaded, though (CPU utulization is under 5%).

My software is nginx-full 1.2.1-2.2+wheezy1, on an amd64 VM.


TIA!


Kind regards,
--Toni++
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2013-11-16 01:08
(Received via mailing list)
On Saturday 16 November 2013 02:24:43 Toni Mueller wrote:
> Unfortunately, I cannot set the variable $pat already in nginx.conf,
>
> 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
A8cae7780631b0e946f4826cd06128a6?d=identicon&s=25 Toni Mueller (Guest)
on 2013-11-16 02:02
(Received via mailing list)
Hi,

On Sat, Nov 16, 2013 at 04:07:19AM +0400, Valentin V. Bartenev wrote:
> 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.

Thanks for the explanation - I did not get that from this page. :/

> 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

Unfortunately, there is nothing between the info (too little) and
debug log levels (too much). But it was fruitful, as I found the
problem. :)


Cheers,
--Toni++
34011bc56457235a2caa5ed1d4a29f3c?d=identicon&s=25 Jonathan Matthews (Guest)
on 2013-11-16 09:13
(Received via mailing list)
On 16 Nov 2013 01:02, "Toni Mueller" <support-nginx@oeko.net> wrote:
> Unfortunately, there is nothing between the info (too little) and
> debug log levels (too much). But it was fruitful, as I found the
> problem. :)

Why don't you let the list know how you fixed it, so the next person
with
the same problem can find the answer in the list archives?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.