I'm using the default nginx package on Ubuntu 14.04 server. It is using /etc/nginx/nginx.conf
as the main config, and then includes configs from /etc/nginx/conf.d/*.conf
and /etc/nginx/sites-enabled/*
.
The default nginx config has this directive for logging to the access log
access_log /var/log/nginx/access.log;
I'd like to add the X-Forwarded-For header, so I do this inside of the conf.d
folder:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
The problem I have is that then I'm getting two records inside my access.log file - one with the header info and another one without.
I know I can overwrite the nginx.conf
file itself, but I'd rather avoid it if possible. I would also like to keep using the same log file (access.log
).
Is there a way to tell nginx to override the previous directive and simply change the log format without modifying the main nginx.conf
file?