nginx: [emerg] duplicate "log_format" name "access"

nginx 在开启多个虚拟主机日志时,会出现以下错误

nginx: [emerg] duplicate "log_format" name "access" in /*****/conf/nginx.conf:97

经研究,nginx.conf配置文件

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log  /home/logs/default.log  access;

在多个access_log 中 使用了同一个log_format access
解决方法:在其它虚拟主机配置文件中,将log_format 更改为其它名称,如下

log_format  access_domain_aaa  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log  /home/logs/domain_aaa.log  access_domain_aaa;

    log_format  access_domain_bbb  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" $http_x_forwarded_for';
    access_log  /home/logs/domain_bbb.log  access_domain_bbb;

重启nginx 即可

添加新评论