47

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 ?

4
  • 1
    did you ever figure this out? having a similar issue here... Commented Nov 6, 2015 at 3:07
  • It worked later on without me changing anything. Commented Nov 6, 2015 at 9:37
  • having same issue no idea what's going on Commented Mar 3, 2016 at 1:13
  • I have this problem too. Nginx is started correctly but I don't see any page when I enter server IP address. and also I don't see any logs in access and error log. Commented Jul 1, 2020 at 9:47

5 Answers 5

66

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
Sign up to request clarification or add additional context in comments.

Comments

19

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

1 Comment

For docker user, if you concern where this behavior is set, visit this Nginx Dockerfile, look for the comment # forward request and error logs to docker log collector
14

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/*

5 Comments

Someone must've set this for it to be used as Docker image
I'm using the official nginx docker image and this is what my problem was. It does make great sense inside of docker, but that was a fun one to find lol
@Freedom_Ben i noticed the same for the official nginx docker image. Could you please help understand why it makes sense inside of docker? Will it be somehow routed to the host? If so, how can I make use of it? Thanks!
@Hans It makes sense in docker because stdout/stderr are the "proper" way to log. In docker world files are a bad idea because they are ephemeral. You want to follow 12-factor app principles
For docker user, if you concern where this behavior is set, visit this Nginx Dockerfile, look for the comment # forward request and error logs to docker log collector
5

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;

Comments

0

Your answer is here

Step1: Open the rsyslog config file

#vi /etc/rsyslog.conf

Step2: Add the following line before the line $IncludeConfig /etc/rsyslog.d/*.conf

$ModLoad imfile

Step3: Create a new file for nginx rsyslog configuration

#vi /etc/rsyslog.d/nginx.conf

Step4: Update the following lines.

# error log
$InputFileName /var/log/nginx/error.log
$InputFileTag nginx:
$InputFileStateFile stat-nginx-error
$InputFileSeverity error
$InputFileFacility local6
$InputFilePollInterval 1
$InputRunFileMonitor

# access log
$InputFileName /var/log/nginx/access.log
$InputFileTag nginx:
$InputFileStateFile stat-nginx-access
$InputFileSeverity notice
$InputFileFacility local6
$InputFilePollInterval 1
$InputRunFileMonitor

Step5: Restart rsyslog service

#service rsyslog restart

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.