nginx : access.log and error.log file empty

2020-06-07 08:03发布

问题:

I have just installed nginx on Ubuntu 14.04 using the command

sudo apt-get install nginx

Now, when I open my browser and type in the address localhost then I am correctly shown the "Welcome to nginx" page. Also, I checked the config file located in /etc/nginx/nginx.conf and found the following log settings:

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

However, when I check these two files, both are empty. I have opened the localhost page multiple times but still the log files are empty. What might be wrong with my setup ?

回答1:

I had the same issue after reinstalling nginx to newer version. Seems like log files ownership changed and new nginx couldn't save anything there.

Removing log files and reloading nginx worked for me:

$ sudo rm -f /var/log/nginx/*
$ sudo nginx -s reload


回答2:

It looks like by default they are set to go to stdout and stderr.

lrwxrwxrwx  1 root root   11 Apr 27  2016 access.log -> /dev/stdout
lrwxrwxrwx  1 root root   11 Apr 27  2016 error.log -> /dev/stderr

So you can remove the symlinks and should be fine.

rm -f /var/log/nginx/*


回答3:

For all of those whose, like me, came here to figure out why the logs file are empty, and did not realise that you might actually be inside a docker container like one of the comments on another answer suggests, just open a new shell and tail the logs with

docker logs {your-container-id-here} -f



标签: nginx