+ -
当前位置:首页 → 问答吧 → 请教:nginx日志记录

请教:nginx日志记录

时间:2010-03-19

来源:互联网

我的日志格式是这样的:
    log_format  main  '$remote_addr - $remote_user [$time_local]  '
                      '"$request_method $scheme://$host$request_uri $server_protocol" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent"';

但是我发现日志中记录的很多内网访问的记录,就是$remote_addr都是192.168.xx.xx这样的记录,因为日志比较大,所以我不想要这部分的记录。
也就是说nginx能否做到根据来源IP来判断是否记录日志呢?像squid的那样?
谢谢!

作者: haoyu323   发布时间: 2010-03-19

i don't know how to solve your problem with log files of nginx.as a system administraor.we should save the entire access log and error day within at least one week.

to prevent your log file from being unlimitedly increased.you have to rotate your log file.
these log files are divided by one day or several hours.to do so.you search the Internet to get help.

作者: todayhero   发布时间: 2010-03-19

感谢todayhero 的回复,但是您说的办法不可行。
毕竟都有自己的需求在,这里的日志是需要每天上传并分析的,并且还要备份。
所以不太希望里面出现大量的无用数据,最笨的办法是在上传前先把不要的数据grep -v掉。
但是我还是希望能通过nginx自己的一些机制来处理。
毕竟grep很不效率。
谢谢!

作者: haoyu323   发布时间: 2010-03-19

I  see.

your requirement is little particular.ordinary OS can not help you.you thoroughly depend on yourself.i don't find out any helps from the manual of nginx documents.if you have the time.you carefully read its manual.

Can you tell me whether the clients of LAN access the specific directory.if the clients of LAN acces the specific content you can separately log their access log.such as

location /foobar {
access_log /var/log/foobar.log;
}

this example indicted the access log of 'footbar' directory is written to foobar.log

if this feature is not built-in you only use third-party tools or program developed by yourself.

good luck.

作者: todayhero   发布时间: 2010-03-19

楼上的英文好像很好哟。嘿嘿向你学习

作者: scyzxp   发布时间: 2010-03-19

回复 5# scyzxp


    thanks for your praise.i am bored to be dead every day.have no alternate but learning english.

作者: todayhero   发布时间: 2010-03-19

location /foobar {
access_log /var/log/foobar.log;
}

perfect !!!
OK!实现分离了,不需要的虽然没有禁止,但是他记录到了另外一个access.log中,这就是我的需要的!
非常感谢todayhero !!
感谢!

作者: haoyu323   发布时间: 2010-03-19

回复 6# todayhero


    我想你应该去翻译一些技术手册这样学习更快。

作者: scyzxp   发布时间: 2010-03-19