nginx : access.log and error.log file empty

2020-06-07 08:18发布

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 ?

标签: nginx
3条回答
Evening l夕情丶
2楼-- · 2020-06-07 08:25

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

查看更多
叼着烟拽天下
3楼-- · 2020-06-07 08:32

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/*
查看更多
姐就是有狂的资本
4楼-- · 2020-06-07 08:47

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
查看更多
登录 后发表回答