Nginx 日志产生大量400错误日志

最近一个打点的日志,发现nginx日志记录里多了很多400错误,没有访问地址。


221.239.20.160 - - [18/Oct/2012:20:00:02 +0800] "-" 400 0 "-" "-" "-"


现象大致:


网页访问的时候马上产生一条正常的访问日志,过个10来s产生400错误日志。

监控浏览器请求在访问网页后没有其他请求,再用网络抓包也没抓到请求记录。

但是这条日志的ip又是本机的


大致原因(nginx不是很熟悉,查查网上的类似情况还比较多):

主要是连接断开

1.浏览器关闭连接断开或长连接断开

2.浏览器的pre-connect引起,简单的说,就是浏览器一开始开了5个连接去取东西,结果只用了2个,3个关闭的时候就出这条日志。

参考:

http://www.homeine.com/2012/04/17/chromefirefox-pre-connection-%E5%AF%BC%E8%87%B4nginx-400%E6%8A%A5%E9%94%99%EF%BC%81/

http://www.oschina.net/question/12_34650


解决方法无非:

1.忽视400错误日志。

2.不让nginx输出这种日志

It's very likely that there's no Host header sent, so it's being directed to the server set as "default".

In my setup i define a server{} section for every real host, and then add a separate "catch all" one for everything else and turn off the logs when not debugging. 


If you are able to do something similar, it should capture those spurious connections, direct them to the default host, and not log the lines


#catch all
    server {
        listen 80 default_server;
        server_name   localhost.domain.com  localhost 127.0.0.1 xx.xx.xx.xx; #where xx.xx.xx.xx is the local IP
        access_log off;
        location / {
            #local
            allow 127.0.0.1;
            #office router
            allow xx.xx.xx.xx;
            #protect 
            deny all;
        }        

    } 


#real server(s)
   server {
      access_log /var/log/nginx/access.log;
      listen 80;
      server_name . domain.com; #matches  www.domain.com and  domain.com
     location / {
        #[..snip..]
     }
   }

参考:http://nginx.2469901.n2.nabble.com/Empty-error-log-lines-a-lot-of-them-td7146725.html


转载于:https://my.oschina.net/greki/blog/84314

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值