nginx之日志路徑配置小知識點


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文件的末尾即可。。

都是粗心惹的禍。。。。。。謹記謹記。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM