Can't log x-forwarded-for

Francis Daly francis at
Tue Aug 2 12:27:52 UTC 2016

On Tue, Aug 02, 2016 at 11:23:46AM +0000, Mik J wrote:

Hi there,

> Thank you very much, it works better, however it works only for access_log for some reason

log_format defines a format that access_log uses.

> 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;

error_log takes and optional "level", but does not take a "format".

> 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 ?

Yes, that piece is acting as it should.


Francis Daly        francis at

More information about the nginx mailing list