nginx: [warn] "log_format" directive used only on "http" level 解決方法
更新時間:2014年08月27日 11:53:39 投稿:junjie
這篇文章主要介紹了nginx: [warn] "log_format" directive used only on "http" level 解決方法,需要的朋友可以參考下
將nginx升級到1.2.4穩(wěn)定版之后,會發(fā)現(xiàn)之前的vhost/*.conf中的日志配置都報了如下的warn:
復(fù)制代碼 代碼如下:
nginx: [warn] the “l(fā)og_format” directive may be used only on “http” level
上網(wǎng)搜索解決方案如下:
將/vhost/xxx.conf里server段里的下面代碼移出該server段即可。
但是這樣的又會產(chǎn)生一個問題,就是各子域名的日志文件都會記錄所有請求的日志,等了好久都沒找到解決方案,后來請教了飛飛之后終于找到解決的方法了。
原來log_format需要在nginx.conf的http層定義,然后在分域名下面就不用定義log_format,直接引用即可,即:
在nginx.conf中http層添加:
復(fù)制代碼 代碼如下:
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中直接寫:
復(fù)制代碼 代碼如下:
access_log ./logs/blog.log Main;
但是注意include vhost/*.conf要放在log_format之后哦,不然會找不到Main的
相關(guān)文章
在Linux系統(tǒng)中將Redmine和SVN整合入Nginx的方法
這篇文章主要介紹了在Linux系統(tǒng)中將Redmine和SVN整合入Nginx的方法,示例基于CentOS系統(tǒng),并用到了Ruby腳本,需要的朋友可以參考下2015-06-06