nginx 日志出错信息 :nginx: [warn] the "log_format" directive may be used only on "http" level一般来说如果nginx的版本...
nginx 日志出错信息 :
nginx: [warn] the "log_format" directive may be used only on "http" level
一般来说如果nginx的版本在1以下,那么不会出错。
对于nginx的新版本,比如1.1.15 ,会出这样的问题,nginx的配置规则有更新,这句话的警告意思是log_format 只能用在 http这个标签中,但是多数情况下,我们有可能在nginx.conf 中include 一个配置文件,在include的配置文件中如果把log_format 放到server 段里,就会出问题,这个在老版本的nginx的语法检查中是不会出错的。
那么好,就把log_format 放到 server 段的前面吧,像这样:
nginx.conf:
include little.conf
---------------------------------------------------------------------------------------------------------------------------------------------------
little.conf:
log_format access '$http_x_forwarded_for $remote_user [$time_local] "http://$host" "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" "$HTTP_X_UP_CALLING_LINE_ID" ';
access_log /usr/local/nginx/logs/access.log access;
server
{
listen 80;
server_name xxx.com;
.....................
[root@t1 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@t1 ~]#
参考:
http://www.a8z8.com/html/2012/tech_1117/46.html
http://www.baibaobing.com/linux/6.html/comment-page-75
http://xiahongyuan.blog.51cto.com/906214/852607