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

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

经研究,nginx.conf 配置文件

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

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

1log_format access_domain_aaa  '$remote_addr - $remote_user [$time_local] "$request" '
2    '$status $body_bytes_sent "$http_referer" '
3    '"$http_user_agent" $http_x_forwarded_for';
4    access_log  /home/logs/domain_aaa.log  access_domain_aaa;
5
6    log_format  access_domain_bbb  '$remote_addr - $remote_user [$time_local] "$request" '
7    '$status $body_bytes_sent "$http_referer" '
8    '"$http_user_agent" $http_x_forwarded_for';
9    access_log  /home/logs/domain_bbb.log  access_domain_bbb;

重启 nginx 即可