Can't log x-forwarded-for

Mik J mikydevel at yahoo.fr
Tue Aug 2 11:23:46 UTC 2016


Hello Francis,
Thank you very much, it works better, however it works only for access_log for some reason
nginx.conf
http {log_format   main    '$remote_addr forwarded for $http_x_real_ip - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"';
sites-available/defaultserver {...access_log /var/log/nginx/default.access.log main;error_log /var/log/nginx/default.error.log;
Witherror_log /var/log/nginx/default.error.log main;
Nginx fails to start# nginx
nginx: [emerg] invalid log level "main" in /etc/nginx/sites-enabled/default:13
The documentation only talks about access_log. Do you think it's normal ?
 

    Le Mardi 2 août 2016 10h00, Francis Daly <francis at daoine.org> a écrit :
 
 

 On Mon, Aug 01, 2016 at 11:25:46PM +0000, Mik J wrote:

Hi there,

> nginx: [emerg] unknown log format "main" in /etc/nginx/sites-enabled/default:8
> 
> in nginx.conf I havehttp {
>     include       mime.types;
>     include       /etc/nginx/sites-enabled/*;
>     include       /etc/nginx/conf.d/*;
>     default_type  application/octet-stream;
>     index         index.html index.htm;
>    log_format   main    '$remote_addr forwarded for $http_x_real_ip - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"';...

Look at the order of config lines there.

You have, effectively,

  http {
    server {
      access_log /tmp/out.log main;
    }
    log_format main '$remote_addr $request';
  }

and nginx complains that "main" is not defined at the "access_log" line.

> i think I did things good but it's like the line in nginx.conf is not taken into account
> Do you know why ?

If you put the "log_format" line before the "server" block (i.e., before
the appropriate "include" line), nginx will probably be happier.

Arguably, since "log_format" is at http-level only, and you can't repeat
"name", nginx *could* be able to handle things out of order. But right
now it doesn't, so the quick fix is to re-order things yourself.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org

_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

 
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160802/967622f9/attachment.html>


More information about the nginx mailing list