2

I'm trying to get nginx to log access and error logs. My logs currently have very old content, a mix of logs and gzipped logs.

$ ls -la access*.log*
-rw-rw-rw- 1 nobody nogroup       0 Jan  8  2016 access.log
-rw-rw-rw- 1 nobody nogroup 2261400 Jan  7  2016 access.log.1
-rw-rw-rw- 1 nobody nogroup  311947 Dec 30  2015 access.log.10.gz
-rw-rw-rw- 1 nobody nogroup  434744 Dec 29  2015 access.log.11.gz

My configuration is:

user www-data www-data;
error_log /var/log/nginx/error.log info;
...
http {
  access_log /var/log/nginx/access.log combined;
...

Strangely, despite the user declaration the worker processes still run as nobody:

# ps -eo "%U %G %a" | grep nginx
root     root     nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
nobody   nogroup  nginx: worker process                                                              
nobody   nogroup  nginx: worker process   

I tried setting the owner of the existing access.log and error.log files to be nobody:nogroup but still it doesn't log anything.

There's nothing (relevant) in syslog.

I have tried a mixture (!) or reloading and restarting nginx after changing the configuration file. Still nothing...

How is my configuration incorrect?

Dan Gravell
  • 243
  • 3
  • 8
  • In the first command block, are you actually in the directory named `/var/log/nginx/`? Also, it's possible that `error_log ` & `access_log` are configured a second time in another file, and the first configuration is ignored. – Stefan Lasiewski Oct 02 '18 at 23:28

2 Answers2

0

You might want to refer to these topics for configuring nginx user:

How do I change the NGINX user?

why do nginx process run with user nobody

About nginx empty logs I suggest you to empty logs directory or temporary disable Selinux to see if it's causing the trouble setenrofce 0

You can also check if you have the right syntax and error_log directive is in the correct place.

Ali Pandidan
  • 1,699
  • 2
  • 9
  • 7
  • Yes, I had reviewed those questions already. As above, I have set the user but it doesn't appear to take effect. I considered a separate "why does the user directive work for me" question but what I actually want to know right now is why the logs don't populate - even with `chmod 777` they still don't work, so I don't think it's permissions. SELinux is not enabled on this system. `nginx -t` reports the configuration is ok. – Dan Gravell Feb 13 '17 at 10:48
  • I also tried clearing out the logs but no difference so far... – Dan Gravell Feb 13 '17 at 10:54
0

I had the exact same issue, and in the end, I went to my root folder and found out there was another access.log file, in a different location and this other one was being written to.

cd /
find . -name 'access.log'
Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42