Skip to content


解决nginx access日志中400 bad request 错误

在access.log中有大量400错误,并以每天几百M的速度增加,占用大量空间.
tail -f /opt/nginx/logs/access.log

116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
119.97.196.7 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
119.97.196.7 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
219.243.95.197 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”

网上大把的文章说是HTTP头/Cookie过大引起的,可以修改nginx.conf中两参数来修正.

client_header_buffer_size 16k;
large_client_header_buffers 4 32k;

修改后

client_header_buffer_size 64k;
large_client_header_buffers 4 64k;

没有效果,就算我把nginx0.7.62升到最新的0.8.54也没能解决.
官方论坛中nginx作者提到空主机头不会返回自定义的状态码,是返回400错误.
http://forum.nginx.org/read.php?2,9695,11560

最后修正如下
改为原先的值

client_header_buffer_size 16k;
large_client_header_buffers 4 32k;

关闭默认主机的日志记录就可以解决问题

server {
listen *:80 default;
server_name _;
return 444;
access_log off;
}

Posted in Nginx, 技术.

Tagged with , .


5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. 死灰 says

    192.168.19.102 – – [12/Jan/2011:17:47:10 +0800] “GET /nagios/cgi-bin/%s%s HTTP/1.1” 400 1015

    我也遇到了这个错误。不过是apache的。现在还没解决呢

  2. Jason Lee says

    我晕,这也叫解决啊!你只是关闭了日志记录

  3. solo says

    忍不住来吐槽一下
    我晕,这也叫解决啊!你只是关闭了日志记录!!!!
    我只能说,作者,i 服了 u

  4. test says

    我靠!楼主真有才

  5. asd says

    應該是 chrome 引起的,關掉無大礙。



Some HTML is OK

or, reply to this post via trackback.