nginx之日誌路徑配置小知識點
阿新 • • 發佈:2021-12-17
1:在nginx的conf檔案中配置了日誌的格式 main或者logstash_json,但是在子配置檔案中一直報錯無效的格式
nginx.conf的配置如下
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; log_format logstash_json'{"@timestamp": "$time_iso8601", ' '"time_local": "$time_local", ' '"remote_addr": "$remote_addr", ' '"remote_user": "$remote_user", ' '"request": "$request", ' '"referer": "$http_referer",' '"request_time": "$request_time", ' '"request_body": "$request_body", ' '"uri": $uri, ' '"status": $status, ' '"logger": "nginx", ' '"agent": "$http_user_agent",' '"scheme": "scheme", ' '"server_name": $server_name, ' '"bytes":$body_bytes_sent, ' '"bytes_sent":$bytes_sent, ' '"http_cookie": $http_cookie, ' '"http_host": $http_host, ' '"http_x_api_method": $http_x_api_method, ' '"http_x_api_sign": "$http_x_api_sign", ' '"http_x_api_userid":$http_x_api_userid, ' '"http_x_forwarded": "$http_x_forwarded_for", ' '"upstr_addr": "$upstream_addr",' '"upstr_host": "$upstream_http_host",' '"upstream_status": "$upstream_status",' '"ups_resp_time": "$upstream_response_time"}'; access_log logs/access.log logstash_json; error_log logs/error.log;
file.conf的配置如下:
access_log /home/logs/nginx/8888.log logstash_json;
但是檢測檔案的時候就是一直報錯,最後才發現問題是:
nginx載入配置的時候從上往下順序載入,載入了子配置檔案conf還沒有載入到日誌格式,所以就是不管什麼格式都是會報錯的,所以在nginx.conf引用外部子配置檔案的時候引用語句include最好放置在nginx.conf檔案的末尾即可。。
都是粗心惹的禍。。。。。。謹記謹記。