Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx : access.log and error.log file empty

Tags:

nginx

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 ?

like image 991
Mandeep Singh Avatar asked Aug 30 '15 18:08

Mandeep Singh


People also ask

What are Nginx access and error logs?

Nginx writes records of its events in two types of logs: access logs and error logs. Access logs write information about client requests, and error logs write information about the server and application issues. This article outlines how to configure and read the Nginx access and error logs.

Where do I find Nginx logs in Linux?

Location of the Log Files By default on most Linux distributions, such as Ubuntu, CentOS, and Debian, access and error logs are located in the /var/log/nginx directory. Reading and Understanding the Nginx Log Files You can open and parse the log files using standard commands like cat, less, grep, cut, awk, and so on.

What to do if Nginx is unable to start or stop running?

Therefore if NGINX is unable to start or abruptly stopped running then you should check the error logs to find more details. You may also find few warnings in the error log but it does not indicate that a problem has occurred but the event may pose a serious issue in the near future.

How do I use the error log?

If you are experiencing errors in your web application, the error log is the first place to start for troubleshooting issues. The error_log directive enables and sets the location and the severity level of the error log. It takes the following form and can be set within an http, server, or location block:


4 Answers

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
like image 130
infografnet Avatar answered Oct 27 '22 04:10

infografnet


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/*
like image 45
Ben Dehghan Avatar answered Oct 27 '22 04:10

Ben Dehghan


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

like image 11
iomv Avatar answered Oct 27 '22 06:10

iomv


By default Nginx image output the logs access/error to stdout/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

We can also check the same by visit this Nginx Dockerfile, look for the comment # forward request and error logs to docker log collector

Now Use the below configuration in order to view the files.

I have changed file name

*error.log = error.logs

access.log = access.logs*

error_log /var/log/nginx/error.logs notice;
access_log /var/log/nginx/access.logs;
like image 2
Yash Tomar -Aeologic Avatar answered Oct 27 '22 04:10

Yash Tomar -Aeologic