# Either error log empty or access log empty

**URL:** <https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206>\
**Category:** NGINX\
**Created:** [March 24, 2012, 1:48am UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206 "2012-03-24T01:48:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 24, 2012, 1:48am UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206/1 "2012-03-24T01:48:51Z")

</div>

hello, I have an nginx/1.0.14 installation with 3 virtual hosts. Each  
virtual hosts features its own error\_log and access\_log, problem is:  
eventhough I have similar log configuration on all virtual hosts either  
access.log is always empty or error.log is always empty on each virtual  
hosts.

I better explain with facts, this is nginx configuration ( I’m just  
copying relevant parts please disregard any syntax error I might have  
introduced by doing this) :

```
    server {
            listen 80 default_server;
            server_name www.HOST_A.com;
            error_log /var/log/nginx/HOST_A.error.log error;
            access_log /var/log/nginx/HOST_A.access.log;
            root /srv/www/HOST_A.com/public_html;
    }
    server {
            listen 80;
            server_name www.HOST_B.com;
            error_log /var/log/nginx/HOST_B.error.log error;
            access_log /var/log/nginx/HOST_B.access.log;
            root /srv/www/HOST_B.com/public_html;
}
    server {
            listen 80;
            server_name www.HOST_C.com;
            error_log /var/log/nginx/HOST_C.error.log error;
            access_log /var/log/nginx/HOST_C.access.log;
            root /srv/www/HOST_C.com/public_html;
}

```

Now, I use wget to make a request for a non existent file and get a 404  
response

wget http://www.HOST\_A.com/nonexistentfile.php  
wget http://www.HOST\_B.com/nonexistentfile.php  
wget http://www.HOST\_C.com/nonexistentfile.php

ls command output shows that for HOST\_A only error.log gets updated, and  
for HOST\_B and HOST\_C only access.log gets updated (I’ve changed  
directory and file owner to nginx user and relaxed permissions but it  
didn’t worked):

-rw-rw-rw- 1 nginx nginx 0 Mar 23 17:28 HOST\_A.access.log  
-rw-rw-rw- 1 nginx nginx 1240 Mar 23 17:52 HOST\_A.error.log  
-rw-rw-rw- 1 nginx nginx 817 Mar 23 17:52 HOST\_B.access.log  
-rw-rw-rw- 1 nginx nginx 0 Mar 23 17:28 HOST\_B.error.log  
-rw-rw-rw- 1 nginx nginx 817 Mar 23 17:48 HOST\_C.access.log  
-rw-rw-rw- 1 nginx nginx 0 Mar 23 17:28 HOST\_C.error.log

As you can see: either .access.log is empty or .error.log  
is empty

This is last line from error log of HOST\_A:

2012/03/23 17:29:12 [error] 3227#0: \*3 open()  
“/srv/www/HOST\_A.com/public\_html/nonexistentfile.php” failed (2: No such  
file or directory), client: XXX.XXX.XXX.XXX, server: www.HOST\_A.com,  
request: “GET /nonexistentfile.php HTTP/1.1”, host: “HOST\_A.com”

and this is last line from access log of HOST\_B ( HOST\_C is identical):  
201.141.61.209 - - [23/Mar/2012:17:52:42 -0600] “GET  
/nonexistentfile.php HTTP/1.1” 404 191 “-” “Mozilla/5.0 (Windows NT 5.1;  
rv:11.0) Gecko/20100101 Firefox/11.0”

In short, I don’t know why only one log file per host gets updated.  
Using htop with “L” option I can verify that the nginx process has all  
log files open and yet it doesn’t write to all of them.

I tried changing file and directory ownership but that didn’t worked ( I  
restarted nginx after those changes). I remember this wasn’t an issue  
when I started using nginx 1.0.11

I’d deeply appreciate any suggestions on this issue

Posted at Nginx Forum:

> **[either error log empty or access log empty](https://forum.nginx.org/read.php?2,224315,224315#msg-224315)**
>
> hello, I have an nginx/1.0.14 installation with 3 virtual hosts. Each virtual hosts features its own error\_log and access\_log, problem is: eventhough I have similar log configuration on all virtual hosts either access.log is always empty or error.log...

---

<div class="post-metadata">

**Author:** ![zhnupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zhnupy](https://www.ruby-forum.com/u/zhnupy)\
**Post date:** [March 24, 2012, 1:46pm UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206/2 "2012-03-24T13:46:39Z")

</div>

On Fri, Mar 23, 2012 at 08:48:11PM -0400, zhnupy wrote:

Hi there,

> eventhough I have similar log configuration on all virtual hosts either  
> access.log is always empty or error.log is always empty on each virtual  
> hosts.

I fail to reproduce the problem you report with the configuration you  
provide.

> I better explain with facts, this is nginx configuration ( I’m just  
> copying relevant parts please disregard any syntax error I might have  
> introduced by doing this) :

Either you’ve left out a relevant part, or there is some other  
difference  
in our test cases. nginx -V, perhaps?

Can you provide a (minimal) config that shows the problem for you?

> Now, I use wget to make a request for a non existent file and get a 404  
> response
> 
> wget http://www.HOST\_A.com/nonexistentfile.php  
> wget http://www.HOST\_B.com/nonexistentfile.php  
> wget http://www.HOST\_C.com/nonexistentfile.php
> 
> ls command output shows that for HOST\_A only error.log gets updated, and  
> for HOST\_B and HOST\_C only access.log gets updated

If nginx returns 404, access\_log should be written.

For HOST\_A, have you any other access\_log defined that is used instead?

If nginx tries to read a missing file, error\_log should be  
written. “try\_files” and “fastcgi\_pass” don’t involve nginx trying to  
read a file. Are you using either of those in the HOST\_B and HOST\_C  
configs? Or have you any other error\_log defined?

> I’d deeply appreciate any suggestions on this issue

More information needed; ideally a config that you confirm shows the  
problem. Does it fail with only one server{} block? Or with two?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![zhnupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zhnupy](https://www.ruby-forum.com/u/zhnupy)\
**Post date:** [March 25, 2012, 10:21pm UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206/3 "2012-03-25T22:21:25Z")

</div>

thanks Francis, after testing one by one it was easier to isolate my  
problem. I have a location definition which turns off the access log,  
but it doesn’t suppose to fire every time, just for specific file  
extensions, here is the entire server block:

52 server {  
53 listen 80 default\_server;  
54 server\_name www.DOMAIN\_A.com _.DOMAIN\_A.com;  
55 error\_log /var/log/nginx/DOMAIN\_A.error.log debug;  
56 access\_log /var/log/nginx/DOMAIN\_A.access.log;  
57  
58 root /srv/www/DOMAIN\_A.com/public\_html;  
59  
60 error\_page 404 /404.html;  
61  
62 location ~_ .(jpg|jpeg|gif|css|png|js|ico|html)$ {  
63 # access\_log off;  
64 expires max;  
65 }  
66  
67 location ~ /.ht {  
68 deny all;  
69 }  
70 }

The desired intention of line 62 is to turn off access log only for  
resources with given extensions, however I found it is firing everytime.

for instance, this URL: http://DOMAIN\_A/aaaa.txt is not supposed to  
fire that rule, but it does. As soon as I comment line 63 (and restart  
nginx) the access log gets updated. I have repeated this several times  
(adding/removing comment in line 63) with same results.

I don’t see nothing wrong with that regular expression, so I’m not sure  
what is going on.

Posted at Nginx Forum:

> **[Re: either error log empty or access log empty](https://forum.nginx.org/read.php?2,224315,224360#msg-224360)**
>
> hello, I have an nginx/1.0.14 installation with 3 virtual hosts. Each virtual hosts features its own error\_log and access\_log, problem is: eventhough I have similar log configuration on all virtual hosts either access.log is always empty or error.log...

---

<div class="post-metadata">

**Author:** ![zhnupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zhnupy](https://www.ruby-forum.com/u/zhnupy)\
**Post date:** [March 26, 2012, 9:26am UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206/4 "2012-03-26T09:26:53Z")

</div>

a very enlightening response

thank you very much Francis!

Posted at Nginx Forum:

> **[Re: either error log empty or access log empty](https://forum.nginx.org/read.php?2,224315,224377#msg-224377)**
>
> hello, I have an nginx/1.0.14 installation with 3 virtual hosts. Each virtual hosts features its own error\_log and access\_log, problem is: eventhough I have similar log configuration on all virtual hosts either access.log is always empty or error.log...

---

<div class="post-metadata">

**Author:** ![zhnupy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@zhnupy](https://www.ruby-forum.com/u/zhnupy)\
**Post date:** [March 26, 2012, 12:12am UTC](https://www.ruby-forum.com/t/either-error-log-empty-or-access-log-empty/218206/5 "2012-03-26T00:12:58Z")

</div>

On Sun, Mar 25, 2012 at 04:20:54PM -0400, zhnupy wrote:

Hi there,

> I have a location definition which turns off the access log,  
> but it doesn’t suppose to fire every time, just for specific file  
> extensions, here is the entire server block:

If you look through the debug log for one request, you’ll see exactly  
why things happen.

When you request “/notthere.php”, it uses the “null” location, and  
returns  
404. Then your error\_page directive causes a rewrite to /404.html, which  
uses the “extensions” location. That is where the request finishes,  
so that is where it is logged. And you have access\_log off there.

> for instance, this URL: http://DOMAIN\_A/aaaa.txt is not supposed to  
> fire that rule, but it does.

It shouldn’t match that rule if it doesn’t generate a 404.

All 404s will match that rule, because of your error\_page configuration.

Maybe you want a separate “location = /404.html{}” block?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
