將nginx升級(jí)到1.2.4穩(wěn)定版之后,會(huì)發(fā)現(xiàn)之前的vhost/*.conf中的日志配置都報(bào)了如下的warn:
代碼如下:
nginx: [warn] the “l(fā)og_format” directive may be used only on “http” level
上網(wǎng)搜索解決方案如下:
將/vhost/xxx.conf里server段里的下面代碼移出該server段即可。
但是這樣的又會(huì)產(chǎn)生一個(gè)問(wèn)題,就是各子域名的日志文件都會(huì)記錄所有請(qǐng)求的日志,等了好久都沒(méi)找到解決方案,后來(lái)請(qǐng)教了飛飛之后終于找到解決的方法了。
原來(lái)log_format需要在nginx.conf的http層定義,然后在分域名下面就不用定義log_format,直接引用即可,即:
在nginx.conf中http層添加:
代碼如下:
log_format Main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for $request_time';
然后在vhost/*.conf中server中直接寫(xiě):
代碼如下:
access_log ./logs/blog.log Main;
但是注意include vhost/*.conf要放在log_format之后哦,不然會(huì)找不到Main的
新聞熱點(diǎn)
疑難解答
圖片精選