Hello!
2015-05-08 12:47 GMT+08:00 FP:
> 现在想实现的目的是,对于不同的user-agent,将访问记录写入到不同的access log
> 用nginx自带的log可以通过if=$*来实现,但是这样就出现一个问题,比如我想把googlebot的写入googlebot.log,就只能采用下面的方法
尽量避免使用 if,我已经反复强调过了 :)
你这里可以使用两个不同的 location,一个是公共入口,一个是 bot 专用。然后,在入口处使用 access_by_lua 进行分发,例如:
location / {
access_by_lua 'if is_bot() then ngx.exec("@bot") end';
# content handler configs for normal traffic
}
location @bot {
# content handler configs for bots
}
Regards,
-agentzh