nginx: [emerg] duplicate “log_format“ name “main“ in /usr/local/phpstudy/vhost/sys/nginx/sys.conf:11
前言
- CentOS Linux release 8.2.2004 (Core)
- phpstdy X1.26
- nginx1.15
配置nginx日志出錯
nginx: [emerg] duplicate "log_format" name "main" in /usr/local/phpstudy/vhost/sys/nginx/sys.conf:8名為 “main” 的 “log_format” 已存在,在/usr/local/phpstudy/vhost/sys/nginx/sys.conf 文件的第 8 行。
錯誤原因
我在nginx的配置文件/usr/local/phpstudy/soft/nginx/nginx-1.15/nginx/conf/nginx.conf中添加了名為 “main” 的 log_format。而/usr/local/phpstudy/vhost/sys/nginx/sys.conf文件已經存在名為 “main” 的 log_format (phpstdy 帶的)。因此產生錯誤:nginx: [emerg] duplicate "log_format" name "main" in /usr/local/phpstudy/vhost/sys/nginx/sys.conf:8。
/usr/local/phpstudy/soft/nginx/nginx-1.15/nginx/conf/nginx.conf的配置如下:
worker_processes auto; user www;error_log logs/error.log;events { use epoll; worker_connections 1024; multi_accept on; }http {lua_package_path "/www/common/waf_lua/?.lua;;";include mime.types;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';gzip on; gzip_buffers 16 8k; gzip_comp_level 2; gzip_min_length 8k; gzip_types text/plain application/javascript text/css; keepalive_timeout 65;client_body_buffer_size 8m; client_header_buffer_size 32k; client_max_body_size 50m;include /usr/local/phpstudy/vhost/sys/nginx/*.conf; include /usr/local/phpstudy/vhost/nginx/*.conf; } stream {include /usr/local/phpstudy/vhost/nginx/*.stream; }/usr/local/phpstudy/vhost/sys/nginx/sys.conf的配置如下:
map $time_iso8601 $logdate {'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;default 'date-not-found';}log_format main '$remote_addr - [$time_local] "$request"'$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_cookie"';access_log logs/access_$logdate.log main;sendfile on;limit_conn_zone $binary_remote_addr zone=perip:10m;limit_conn_zone $server_name zone=perserver:10m;proxy_cache_path proxy_cache levels=1:2 keys_zone=cache_one:100m inactive=2d max_size=1g;lua_shared_dict limit 50m;lua_shared_dict servers 1m;解決辦法
保留一個名為 “main” 的 “log_format” 。
引申一個問題:如果想要為每個 server(或 vhost) 指定一個日志格式該如何?
定義不同名字的"log_format"。
比如,定了2個日志格式,分別名為server1、server2。
log_format server1 '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';log_format server2 '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';為每個 server指定一個日志格式。
server {...access_log /spool/vhost/logs/server1/access.log server1;... } server {...access_log /spool/vhost/logs/server2/access.log server2;... }參考
http://nginx.org/en/docs/http/ngx_http_log_module.html
總結
以上是生活随笔為你收集整理的nginx: [emerg] duplicate “log_format“ name “main“ in /usr/local/phpstudy/vhost/sys/nginx/sys.conf:11的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 迅雷网盘如何下载文件到本地
- 下一篇: nginx log_format 中的变