社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
log_format:
Syntax: |
log_format name [escape=default|json|none] string ...; |
Default: |
log_format combined "..."; |
Context: |
http |
log_format-关键字 name-自定义变量
[escape=default|json|none] string ...-日志具体内容,即HTTP请求变量、nginx内置变量、自定义变量组成
log_format combined "..."-日志默认值
http-只能配置在http作用域下配置
/var/log/nginx/error.log-日志路径
warn-日志级别
main-自定义变量标识
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
-日志内容,即HTTP请求变量、nginx内置变量、自定义变量组成
access.log-关键字,即访问日志
/var/log/nginx/access.log-日志路径
main-日志格式标识符,即引用的是log_format中自定义日志main变量
$arg_PARAMETER #这个变量包含GET请求中,如果有变量PARAMETER时的值。
$args #这个变量等于请求行中(GET请求)的参数,例如foo=123&bar=blahblah;
可以访问nginx官网查看:http://nginx.org/en/docs/http/ngx_http_core_module.html
配置$foo=hello
location /test {
set $foo hello;
echo "foo: $foo";
}
输出
[root@localhost html]# nginx -s reload
[root@localhost html]# curl localhost/test
foo: hello
增加HTTP请求变量演示:arg_PARAMETER、http_HEADER、sent_http_HEADER配置
'"$arg_wd"-"$args"-"$http_x_requested_with"-"$sent_http_cache_control"-"$http_host"-"$sent_http_last_modified" '
nginx -t -c /etc/nginx/nginx.conf
nginx -s reload -c /etc/nginx/nginx.conf
使用curl -v http://localhost:80?wd=wwl&lover=xq测试
进入到/var/log/nginx/access.log目录下访问
验证access_log访问日志格式是否生效:
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!