將nginx升級到1.2.4穩定版之后,會發現之前的vhost/*.conf中的日志配置都報了如下的warn:
代碼如下:
nginx: [warn] the “log_format” directive may be used only on “http” level
上網搜索解決方案如下:
將/vhost/xxx.conf里server段里的下面代碼移出該server段即可。
但是這樣的又會產生一個問題,就是各子域名的日志文件都會記錄所有請求的日志,等了好久都沒找到解決方案,后來請教了飛飛之后終于找到解決的方法了。
原來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中直接寫:
代碼如下:
access_log ./logs/blog.log Main;
但是注意include vhost/*.conf要放在log_format之后哦,不然會找不到Main的
新聞熱點
疑難解答