nginx1.2.4: [warn] “log_format” directive used only on “http

來源:互聯網
上載者:User

nginx1.2.4: [warn] “log_format” directive used only on “http” level 錯誤解決辦法,有需要的朋友可參考一下。

將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的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.