Either error log empty or access log empty

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:

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. [email protected]

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:

a very enlightening response

thank you very much Francis!

Posted at Nginx Forum:

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. [email protected]