故障描述:
在添加Nginx的子配置文件后报错误nginx: [emerg] unknown log format "main"
首先放的 开 log_format 的注释
无法重新加载,仔细查看配置没有语法错误经过调试才发现是定义log_format的时候写到HTTP模块最下面,导致子配置文件无法识别。
http { #配置http服务器的主要段
include mime.types;
default_type application/octet-stream;
include vhost/*.conf; #这样可以在vhost 下面创造多个conf文件
proxy_cache_path /gongju/nginx-1.15.2/conf/confproxy_cache levels=1:2 keys_zone=mycache:10m max_size=10g inactive=60m use_temp_path=off;
# 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 logs/access.log main;
我是先引入了子配置文件然后才定义日志格式,所以报无法识别
解决方法:
将log_format 写到http开头
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 logs/access.log main;
include mime.types;
default_type application/octet-stream;
include vhost/*.conf; #这样可以在vhost 下面创造多个conf文件
proxy_cache_path /gongju/nginx-1.15.2/conf/confproxy_cache levels=1:2 keys_zone=mycache:10m max_size=10g inactive=60m use_temp_path=off;