I want to log custom headers from clients requests. I have added "$http_my_header" to my log_format and it is logged nicely for POST requests. All GET request, on the other hand, a logged with empty value.

The example of GET request:

GET /pws HTTP/1.1
upgrade: websocket
connection: Upgrade
sec-websocket-key: XXXX
host: XXXX
sec-websocket-origin: XXXX
sec-websocket-version: 13
X-Plumbr-sessionId: XXXX
X-Plumbr-accountId: XXXX
X-Plumbr-build: SNAPSHOT

My nginx log_format contains

"$http_x_plumbr_accountid" "$http_x_plumbr_build" 

Does logging headers in GET requests require some special configuration?

  • It doesn't typically require any special configuration. You might want to add an example request to the question, as well as the nginx config (redacted where appropriate). – alienth Sep 24 '15 at 7:54
  • Updated my question, @alienth – Nikem Sep 24 '15 at 9:53

I don't know how much this will help, but for what it's worth, here is a working server block configuration that I was using to set request headers via standard request variables and proxy them onto an IIS server, where they were correctly received and interpreted. I'm sure you could do the same by utilizing these variables (or the ones you need) to include in your access logs by consulting the Nginx documentation to see what all variables are available. Here is the server block I was using:

server {
        listen       8001;
        server_name  localhost;
        location / {
            proxy_set_header  x-client-IP      $remote_addr;
            proxy_set_header  x-forwarded-for  $proxy_add_x_forwarded_for;
            proxy_set_header  host             $http_host;

Depending on where you set your log format and create and/or grab header values, the same should work. You can also use logic for request type, which is something you may want to look into if GET seems to be working and POST is giving unexpected behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.