Nginx日志时间添加毫秒显示
· 技术积累 · Nginx

nginx默认日志格式中,时间只有年月日时分秒,没有到毫秒级别

修改nginx配置文件日志格式,增加毫秒变量 $msec ngx_http_core_module.html#var_msec

# 修改前
    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  main  '$remote_addr - $remote_user [$time_local.$msec] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

查看访问日志,可以看到日志中请求中已有毫秒时间戳

Nginx日志时间添加毫秒显示


本文最后更新时间 2024-03-30
文章链接地址:
https://me.jinchuang.org/archives/896.html
本站文章除注明[转载|引用],均为本站原创内容,转载前请注明出处
Nginx 配置 Referer 防盗链
MAXMIND 免费的GeoLite2数据库分享
不允许空 Referer访问,可以使用反向代理解决
在Nginx中配置使用Geoip2模块

Shell中使用变量作为变量名

Teambition网盘

我要留言