Force Nginx to log error?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Force Nginx to log error?

Carl Winbäck
Hi folks,

Is there any surefire way to force Nginx to log an error?

Perhaps some carefully crafted GET request or similar.

The reason I’m asking is that I’m doing a lab with Nginx’ error
log. Therefore I would like to find a way so that I can force Nginx to
log an error. E.g. if I specify "error_log /srv/nginx/error.log warn;"
then I would like to verify that errors end up in the file that I
specified.


Best regards,
Carl
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Force Nginx to log error?

lists@lazygranch.com
I'm not sure I understand the question, but how does this sound? I use a map to catch requests that I don't want. For instance I return a 444 if I receive a "wget".





          Original Message  


From: [hidden email]
Sent: June 14, 2020 5:40 AM
To: [hidden email]
Reply-to: [hidden email]
Subject: Force Nginx to log error?


Hi folks,

Is there any surefire way to force Nginx to log an error?

Perhaps some carefully crafted GET request or similar.

The reason I’m asking is that I’m doing a lab with Nginx’ error
log. Therefore I would like to find a way so that I can force Nginx to
log an error. E.g. if I specify "error_log /srv/nginx/error.log warn;"
then I would like to verify that errors end up in the file that I
specified.


Best regards,
Carl
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Force Nginx to log error?

Carl Winbäck
> I'm not sure I understand the question, but how does this sound? I
> use a map to catch requests that I don't want. For instance I return
> a 444 if I receive a "wget".

No, I don’t mean status codes on the HTTP level. Status code 444 is
not an error per se that would be sent to the error log, it is a valid
status code sent from the server to the client. To the client that
might be considered an error, but not to Nginx.

I mean errors on a lower level, i.e. the level of the nginx daemon
itself.

E.g. stuff like this:

2020/06/14 13:13:59 [alert] 700#700: *998 open socket #13 left in connection 11
2020/06/14 13:13:59 [alert] 700#700: *4118 open socket #4 left in connection 13
2020/06/14 13:13:59 [alert] 700#700: *4169 open socket #17 left in connection 16
2020/06/14 13:13:59 [alert] 700#700: aborting

It would be useful to me to be able to trigger such messages, so that
I can verify that they are sent to the right destination.

E.g. if I have the following stanza in my config:

error_log /srv/nginx/error.log warn;

Then messages of the warn/error/crit/alert/emerg levels should be
logged and written to the file /srv/nginx/error.log (a file which is
separate from the access log).

I hope it is clearer now what I meant :)
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Force Nginx to log error?

lists@lazygranch.com
That clears it up. Most of what I see in the error log is stuff I have no idea how to fix. I will Google some errors and see what is fixable. The deal is my websites work for me and I get no complaints.

Reading questions on the interwebs, most people get error messages when they use curl on their website. Now I never saw a post where someone intentionally causes an error with curl, but why not. Basically use curl to do something a bad browser would do.

Oh yeah I trap curl too. I used to see strange stuff in the log file from curl use so I put it in the map.

Maybe there is a test suite for this on GitHub.





  Original Message  


From: [hidden email]
Sent: June 14, 2020 8:34 AM
To: [hidden email]
Reply-to: [hidden email]
Subject: Re: Force Nginx to log error?


> I'm not sure I understand the question, but how does this sound? I
> use a map to catch requests that I don't want. For instance I return
> a 444 if I receive a "wget".

No, I don’t mean status codes on the HTTP level. Status code 444 is
not an error per se that would be sent to the error log, it is a valid
status code sent from the server to the client. To the client that
might be considered an error, but not to Nginx.

I mean errors on a lower level, i.e. the level of the nginx daemon
itself.

E.g. stuff like this:

2020/06/14 13:13:59 [alert] 700#700: *998 open socket #13 left in connection 11
2020/06/14 13:13:59 [alert] 700#700: *4118 open socket #4 left in connection 13
2020/06/14 13:13:59 [alert] 700#700: *4169 open socket #17 left in connection 16
2020/06/14 13:13:59 [alert] 700#700: aborting

It would be useful to me to be able to trigger such messages, so that
I can verify that they are sent to the right destination.

E.g. if I have the following stanza in my config:

error_log /srv/nginx/error.log warn;

Then messages of the warn/error/crit/alert/emerg levels should be
logged and written to the file /srv/nginx/error.log (a file which is
separate from the access log).

I hope it is clearer now what I meant :)
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Force Nginx to log error?

J.R.
In reply to this post by Carl Winbäck
Mmmm... If you set it to debug you would probably get something to pop
up sooner rather than later....

My error log level is set to 'error' and I typically see some ocsp
cert timeouts and the occasional client exceeding my request (rate)
limit settings... Not a lot ends up in the nginx error log (at least
not at the level I use)...

Setting up rate limiting is just a few lines in the config, then you
can hit a page with curl or wget and force it to trigger which would
end up in the error log...

If you have something invalid in your config and do a restart, it will
also write that into the error log...
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Force Nginx to log error?

Carl Winbäck
In reply to this post by Carl Winbäck
On Sun, 14 Jun 2020 at 17:34, Carl Winbäck <[hidden email]> wrote:
> It would be useful to me to be able to trigger such messages, so that
> I can verify that they are sent to the right destination.

I found a simple way to trigger a message to the error log, so I
thought I’d share it in case someone also has use for this.

If the root of your site is /foo/mysite/ create an empty directory
there, e.g. /foo/mysite/xyzzy

Do *not* create any index file there, e.g. no index.html or index.php

Now you request that URL via any client of your choice, e.g. curl:

curl https://mysite.example.com/xyzzy/

That request will trigger a message to the error log that looks like
this:

2020/06/20 07:30:04 [error] 694#694: *835 directory index of
  "/foo/mysite/xyzzy/" is forbidden, client: 172.16.3.248, server: ,
  request: "GET / HTTP/1.0"


Best regards,
Carl
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx