andy27367451 发表于 2018-11-11 09:17:18

nginx unknow log_format access in www.conf解决方法

  今天遇到一个很奇怪的问题:不管在nginx.conf里面打开什么格式的日志格式,在www.conf里面都是不知道的日志格式。具体如下:nginx.conf
  include       vhost/*.conf;
  log_format main '$remote_addr - $remote_user [$time_local] '
  '"$request" $status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"' ;
  log_format access '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent"' ;
  在nginx.conf文件里面的日志可以使用main,access日志格式,但是换到vhost下面的conf文件就不能用了,不管什么格式:www.conf
  加上日志格式:
  access_log/www/logs/sunrise.r.xiujj.cn.log access;
  测试的时候就会提示:
  nginx: unknown log format "access" in /etc/nginx/conf/vhost/www.conf:3
  nginx: configuration file /etc/nginx/conf/nginx.conf test failed
  百度,谷歌全部千遍一律都是log_format没有打开的原因。
  后来在阿里上提交工单,阿里工程师说是因为在上面include vhost/*.conf,然后再配置的日志格式。
  加载配置的时候从上顺序加载,加载了conf还没有加载到日志格式,所以就是不管什么格式都是:
  nginx: unknown log format
  把include放到最后面就可以了。。。
  记录一下。都是不细心。。。以后得注意

页: [1]
查看完整版本: nginx unknow log_format access in www.conf解决方法