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

推荐订阅源

B
Blog
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
量子位
A
About on SuperTechFans
The Register - Security
The Register - Security
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
Hacker News: Ask HN
Hacker News: Ask HN
T
The Exploit Database - CXSecurity.com
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 司徒正美
NISL@THU
NISL@THU
V2EX - 技术
V2EX - 技术
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Schneier on Security
Schneier on Security
博客园 - 三生石上(FineUI控件)
T
The Blog of Author Tim Ferriss
AWS News Blog
AWS News Blog
The GitHub Blog
The GitHub Blog
C
Cisco Blogs
T
Tenable Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Vulnerabilities – Threatpost
美团技术团队
L
LangChain Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
P
Privacy International News Feed
Spread Privacy
Spread Privacy
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
S
Security @ Cisco Blogs

web 服务器 on 打工人日志

使用TLSv1.3 升级nginx和openssl nginx 配置和编译 nginx ssh-key connection exception nginx 编译参数详解 nginx 重写规则 rewrite模块 nginx.conf 配置文件详解 nginx 汇总
nginx 日志格式整理
2021-12-13 · via web 服务器 on 打工人日志

nginx 日志配置

语法

access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]]; # 设置访问日志
access_log off; # 关闭访问日志

例子:

access_log /var/logs/nginx-access.log
access_log /var/logs/nginx-access.log buffer=32k gzip flush=1m

使用 log_format 自定义日志格式

Nginx 预定义了名为 combined 日志格式,如果没有明确指定日志格式默认使用该格式:

log_format combined '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

如果不想使用 Nginx 预定义的格式,可以通过 log_format 指令来自定义。

语法

log_format name [escape=default|json] string ...;
变量含义
$bytes_sent发送给客户端的总字节数
$body_bytes_sent发送给客户端的字节数,不包括响应头的大小
$connection连接序列号
$connection_requests当前通过连接发出的请求数量
$msec日志写入时间,单位为秒,精度是毫秒
$pipe如果请求是通过 http 流水线发送,则其值为"p",否则为“."
$request_length请求长度(包括请求行,请求头和请求体)
$request_time请求处理时长,单位为秒,精度为毫秒,从读入客户端的第一个字节开始,直到把最后一个字符发送张客户端进行日志写入为止
$status响应状态码
$time_iso8601标准格式的本地时间,形如“2017-05-24T18:31:27+08:00”
$time_local通用日志格式下的本地时间,如"24/May/2017:18:31:27 +0800"
$http_referer请求的 referer 地址。
$http_user_agent客户端浏览器信息。
$remote_addr客户端 IP
$http_x_forwarded_for当前端有代理服务器时,设置 web 节点记录客户端地址的配置,此参数生效的前提是代理服务器也要进行相关的 x_forwarded_for 设置。
$request完整的原始请求行,如 “GET / HTTP/1.1”
$remote_user客户端用户名称,针对启用了用户认证的请求
$request_uri完整的请求地址,如 “https://daojia.com/"

例子:

access_log /var/logs/nginx-access.log main
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';