惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 最新话题
Help Net Security
Help Net Security
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
S
SegmentFault 最新的问题
J
Java Code Geeks
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
博客园_首页
H
Hacker News: Front Page
T
Threatpost
Jina AI
Jina AI
博客园 - Franky
月光博客
月光博客
L
LINUX DO - 热门话题
The Cloudflare Blog
H
Heimdal Security Blog
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
S
Secure Thoughts
T
Tenable Blog
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 个人网站安全防护 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法 券商费率调整记 迷你主机组装记 Labwc更换定制皮肤 树莓派跑分流代理 实用自动代理配置示例 九年老鼠标复活记 Openvpn示例 Mac下如何旋转webp图片 如何隐藏Vscode中Markdown PDF插件的头部内容 解决Linux下网络配置无法变更保存的问题 labwc环境启用wlogout Ubuntu下新官方微信尝鲜 简单检测用户是否开启广告屏蔽 Atuin ZFS下卡顿问题解决 Wine安装64位微信 Fish 和 Atuin使用记 Fastapi简单实现临时下载链接 Fastapi微信公众号开发简要 Hugo根据语种展示不同内容 如何修复Waybar微信图标错误 信封加密简要 Linux环境下维护公众号记录 快速隐藏和呼出终端 Wayland环境自动切换壁纸 SuperTuxKart 试玩 简单抓取雪球股票快讯 为什么你的kill命令不能列出信号表 Wine安装微信保姆教程 Hysteria科学上网简要 Ubuntu 23.10 钉钉无法启动解决方法 网站导航栏防止插入Adsense自动广告 Linux环境按键检测 Hugo文末添加最后修改时间 Wayland环境ksnip无法复制问题解决 我眼中的股票市场 Caddy简单图片防盗链 greetd和regreet使用教程 Wayland环境下截图加后期修改 Wayland 环境下gif录屏 Firefox的一些有趣功能 Ubuntu 切换系统语言 Firefox 标题栏高度调整 网站添加回到顶部功能 Hugo自定义字体 Labwc 便捷配置 Wofi使用教程 窗口管理器labwc使用记 文件共享软件Dufs推荐 Hugo静态站点接入Adsense广告 Fcitx5配置详解 Ubuntu安装chrome的方法总结 一种Xterm.js的全屏方案 Google网址收录api Python示例 手机听离线音乐 Snipe it资产导入 应用启动器yofi使用配置 Snipe it资产管理系统安装使用 Ubuntu开机启动加速 Vue3 vite TypeScript跨域等相关设置 Ubuntu手动升级Libreoffice Ubuntu设置alacritty为默认终端 简体文章批量转换为繁体 使用Inkscape调整svg图片大小 实用命令 使用mitmproxy给手机app抓包 Python中rstrip方法细解 Github同主机多仓库部署deploy key问题处理 Linux安装最新版本Python KeePassXC使用教程 Ubuntu 22.10连接蓝牙耳机报错br-connection-profile-unavailable解决方法
Caddy日志配置轮转和格式化
2022-10-19 · via mephisto.cc

Nginx 日志配置方式灵活多变,caddy 日志配置也类似,示例如下,重点为轮转和部分格式调整:

 1mephisto.cc {
 2
 3    ... 战术省略 ...
 4
 5    log {
 6        output file /var/log/caddy/mephisto.cc.log {
 7            roll_size 10mb
 8            roll_keep 20
 9            roll_keep_for 7d
10        }
11        format json {
12            time_local
13            time_format wall_milli
14        }
15    }
16}

1. 示例解释:

output <writer_module>

此处 <writer_module> 可以是:stderr | stdout | discard | file | net, 分别表示:输出到 标准错误 | 标准输出 | 放弃(勤俭持家,不高兴不要日志啦!) | 文件 | 网络地址(比如 syslog 等), 示例为输出到本地文件 /var/log/caddy/mephisto.cc.log

输出目标为 file 的时候,可配选项为:

  • roll_disabled

    关闭轮转,会导致磁盘写满告警,除非你有其它兜底方式解决 或者 不在乎这个问题,否则不要配置。 disables log rolling. This can lead to disk space depletion, so only use this if your log files are maintained some other way.

  • roll_size

    文件大小多大开始轮转,单位 megabyte,小数值向上取整,默认 100M is the size at which to roll the log file. The current implementation supports megabyte resolution; fractional values are rounded up to the next whole megabyte. For example, 1.1MiB is rounded up to 2MiB. Default: 100MiB

  • roll_uncompressed

    是否开启 gzip 压缩 turns off gzip log compression. Default: gzip compression is enabled.

  • roll_local_time

    轮转后的文件名所带时间的格式是否设置为本地格式,默认 utc time sets the rolling to use local timestamps in filenames. Default: uses UTC time.

  • roll_keep

    保留多少个轮转文件 is how many log files to keep before deleting the oldest ones. Default: 10

  • roll_keep_for

    轮转后的文件保留多长时间,d 或者 h,看下面引文解释,懒得翻译了 默认:2160h(90 天) is how long to keep rolled files as a duration string. The current implementation supports day resolution; fractional values are rounded up to the next whole day. For example, 36h (1.5 days) is rounded up to 48h (2 days). Default: 2160h (90 days)

2. 示例解释

format <encoder_module>

此处 <encoder_module> 可以是:** console | json | filter 等

json 表示日志会输出为 json 格式,一行一个:

1{"level":"info","ts":1654008681.039981,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_ip":"2001:19f0:7001:2e1:5400:3ff:fe45:eb38","remote_port":"55598","proto":"HTTP/2.0","method":"GET","host":"mephisto.cc","uri":"/icons/favicon-32x32.png","headers":{"User-Agent":["Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1"],"Accept-Language":["en-US,en;q=0.9"],"Referer":["https://mephisto.cc/"],"Cookie":[],"Accept":["*/*"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mephisto.cc"}},"user_id":"","duration":0.000274438,"size":2057,"status":200,"resp_headers":{"Content-Length":["2057"],"Server":["Caddy"],"Etag":["\"rcr3nq1l5\""],"Content-Type":["image/png"],"Last-Modified":["Tue, 31 May 2022 14:16:38 GMT"]}}
2{"level":"info","ts":1654008688.0219219,"logger":"http.log.access.log1","msg":"handled request","request":{"remote_ip":"2001:19f0:7001:2e1:5400:3ff:fe45:eb38","remote_port":"55596","proto":"HTTP/2.0","method":"GET","host":"mephisto.cc","uri":"/images/sun.svg","headers":{"Cookie":[],"Accept":["image/webp,image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5"],"Accept-Encoding":["gzip, deflate, br"],"User-Agent":["Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1"],"Accept-Language":["en-US,en;q=0.9"],"Referer":["https://mephisto.cc/"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mephisto.cc"}},"user_id":"","duration":0.000658347,"size":1268,"status":200,"resp_headers":{"Server":["Caddy"],"Etag":["\"rcr3nq2x7\""],"Content-Type":["image/svg+xml"],"Last-Modified":["Tue, 31 May 2022 14:16:38 GMT"],"Content-Encoding":["gzip"],"Vary":["Accept-Encoding"]}}

每种类型有多个配置项:

  • time_local 日志里面 ts 这个字段的格式跟随系统的本地时间格式,默认 Logs with the local system time rather than the default of UTC time.

  • time_format

    • wall_milli 时间格式:2006/01/02 15:04:05.000,我选的这个,比较符合中国大陆习惯。

调整后日志示例为(实际不会换行,这里只是格式化方便阅读):

 1{
 2  "level": "info",
 3  "ts": "2022/10/19 05:56:12.777",
 4  "logger": "http.log.access.log1",
 5  "msg": "handled request",
 6  "request": {
 7    "remote_ip": "2409:891f:1ae7:8859:c1b0:fe4f:15ed:bcfa",
 8    "remote_port": "49577",
 9    "proto": "HTTP/2.0",
10    "method": "GET",
11    "host": "mephisto.cc",
12    "uri": "/images/geo_data_viewer_3d.webp",
13    "headers": {
14      "Referer": ["https://mephisto.cc/tech/gpx/"],
15      "Cookie": [],
16      "Accept": [
17        "image/webp,image/avif,video/*;q=0.8,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"
18      ],
19      "Accept-Encoding": ["gzip, deflate, br"],
20      "User-Agent": [
21        "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1"
22      ],
23      "Accept-Language": ["en-US,en;q=0.9"]
24    },
25    "tls": {
26      "resumed": false,
27      "version": 772,
28      "cipher_suite": 4865,
29      "proto": "h2",
30      "server_name": "mephisto.cc"
31    }
32  },
33  "user_id": "",
34  "duration": 0.002766397,
35  "size": 128076,
36  "status": 200,
37  "resp_headers": {
38    "Access-Control-Allow-Origin": ["*"],
39    "Etag": ["\"rjw2fi2qto\""],
40    "Content-Type": ["image/webp"],
41    "Accept-Ranges": ["bytes"],
42    "Server": ["Caddy"],
43    "Cache-Control": ["max-age=1705200"],
44    "Last-Modified": ["Mon, 17 Oct 2022 08:33:18 GMT"],
45    "Content-Length": ["128076"],
46    "Alt-Svc": ["h3=\":443\"; ma=2592000"]
47  }
48}

当然其它可配选项还有很多,看不明白的可以测试选择适合自己的。官方文档链接为:https://caddyserver.com/docs/caddyfile/directives/log , 个人小站,这样配置已经够用了。

另外,服务器调整时区相关如下

1sudo timedatectl set-timezone your_time_zone

例如,想要将系统时区设置为 Asia/Shanghai:

1sudo timedatectl set-timezone Asia/Shanghai

时区列表获取过滤:

1sudo timedatectl list-timezones |grep -i shanghai

查看结果 timedatectl:

1➜  timedatectl
2
3            Local time: Wed 2022-10-19 16:14:21 CST
4        Universal time: Wed 2022-10-19 08:14:21 UTC
5              RTC time: Wed 2022-10-19 08:14:21
6            Time zone: Asia/Shanghai (CST, +0800)
7System clock synchronized: yes
8            NTP service: active
9        RTC in local TZ: no