Nginx Logging exclusion help

Hi,

I am quite new to NGINx; but have used this for pop proxy; light
web-servers & quite fascinated with the results.

Right now facing part as far logging is concerned. I certain
hits in logs; which are just opening connections & dont transmit
anything & close the connection or are disconnected after
time-outs. So some entries of no requests format & error as 408 get
recorded in logs; which makes centralised logging system go hay-wire.

I would like to avoid logging such entries as done in apache;
which does not logs 400 or 408 or any telnet requests w/o passing any
headers.

Some of options tried are as follows (but havent helped) :

If request not as GET / POST / HEAD request methods

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;

Access log:

log_format main '$remote_addr - $remote_user [$time_local] “$request”

                '$status $body_bytes_sent "$http_referer" '

                '"$http_user_agent" "$http_cookie" ';

Detailed Logs:

89.5.0.243 - - [25/May/2009:14:27:54 +0530] “-” 408 0 “-” “-” “-”
XXX.XXX.XXX.5 - - [25/May/2009:14:26:32 +0530] “GET /health.htm
HTTP/1.1” 200 3 “-” “-” “-”
XXX.XXX.XXX.6 - - [25/May/2009:14:26:23 +0530] “GET /health.htm
HTTP/1.1” 200 3 “-” “-” “-”
67.161.28.173 - - [25/May/2009:14:26:22 +0530] “-” 400 0 “-” “-” “-”

In order to replicate this scenario; just try telneting to your Nginx
server:port & disconnect w/o passing any request of GET/POST; you would
have 400 error in logs.

Conf Details:

user nobody;
worker_processes 10;

error_log /var/log/nginx/logs/error_log debug;
pid /var/log/nginx/logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

Timeouts

client_body_timeout 120;
client_header_timeout 120;
keepalive_timeout 5 5;
send_timeout 5;

General Options

ignore_invalid_headers on;
limit_zone gulag $binary_remote_addr 1m;
recursive_error_pages on;
sendfile on;
server_name_in_redirect off;
server_tokens off;

TCP options

tcp_nodelay on;
tcp_nopush on;

Logging & Formats

log_format main '$remote_addr - $remote_user [$time_local]
“$request” ’
'$status $body_bytes_sent “$http_referer” ’
'“$http_user_agent” “$http_cookie” ';
server {
listen 8081;
server_tokens off;
server_name metrics.example.com metric.example.com;
access_log /var/log/httpd/logs/example/access_log main;

location / {
root   /home/httpd/html/example;
index  index.php index.html;

If request not as GET , HEAD, POST request methods dont log the

requests
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
access_log off;
}
if ($host ~ “^(.*)example.com”) {
rewrite . /blank.html break;
expires -1;
}
}
}

Any help you would be highly appreciable.

Regards,
Sandesh K

Posted at Nginx Forum: