码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx报错nginx: [emerg] unknown log format "main"

时间:2015-07-10 16:55:27      阅读:923      评论:0      收藏:0      [点我收藏+]

标签:nginx

故障描述:

  在添加Nginx的子配置文件后报错误nginx: [emerg] unknown log format "main" 

  无法重新加载,仔细查看配置没有语法错误经过调试才发现是定义log_format的时候写到HTTP模块最下面,导致子配置文件无法识别。


错误的写法

  include /opt/app/nginx/conf/conf.d/*.conf;



  log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                    ‘$status $body_bytes_sent "$http_referer" ‘
                    ‘"$http_user_agent" "$http_x_forwarded_for"‘;

  access_log  /opt/logs/nginx/access.log  main;


}

我是先引入了子配置文件然后才定义日志格式,所以报无法识别


解决方法:

将log_format 写到http开头

http
{

  log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                    ‘$status $body_bytes_sent "$http_referer" ‘
                    ‘"$http_user_agent" "$http_x_forwarded_for"‘;

  access_log  /opt/logs/nginx/access.log  main;







本文出自 “Linux SA John” 博客,请务必保留此出处http://john88wang.blog.51cto.com/2165294/1672876

Nginx报错nginx: [emerg] unknown log format "main"

标签:nginx

原文地址:http://john88wang.blog.51cto.com/2165294/1672876

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!