网站首页 > 技术教程 正文
日志功能在ngx_http_log_module模块中定义,实现了以指定格式写入请求日志。
我们先来看一个nginx配置文件:
http {
include mime.types;
default_type application/octet-stream;
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $http_host $name $id';
map $http_host $name {
hostnames;
default 0;
www.example.com 1;
}
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
if ($http_cookie ~* "id=(\S+) {
set $id $1;
}
access_log log/www.example.com_access.log custom;
location / {
root html;
try_files $uri /index.html;
}
}
}
nginx 日志相关指令
access_log指令第一个参数定义了日志文件名和写入位置,第二个参数是日志格式名称。适用于http, server, location, if in location, limit_except上下文
access_log log/www.example.com_access.log custom;
log_format指令定义日志输出格式。适用于http上下文。
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $http_host $name $id';
日志格式中预定义变量
$name $id这两个变量是在配置文件里面自定义的。自定义变量的方法大家可以参考上一篇《nginx入门——预定义变量和自定义变量(五)》。
猜你喜欢
- 2024-10-11 CentOS中Nginx日志自动分割及日志分析
- 2024-09-21 滚动 docker 中的 nginx 日志,竟然如此简单
- 2024-09-21 Nginx Access Log日志统计分析常用命令
- 2024-09-21 GoAccess - 实时 Apache 和 Nginx 日志分析工具
- 2024-09-21 滚动 docker 中的 nginx 日志思路详解
- 2024-09-21 一项一项教你测等保2.0——Nginx中间件
- 2024-09-21 Nginx 日志文件详解:监控与诊断利器
- 2024-09-21 logrotate轮转nginx日志(nginx轮询)
- 2024-09-21 centos7系统nginx的 日志清理(nginx关闭日志记录)
- 2024-09-21 通过filebeat、logstash、rsyslog 几种方式采集 nginx 日志
你 发表评论:
欢迎- 最近发表
-
- Linux新手必看:几种方法帮你查看CPU核心数量
- linux基础命令之lscpu命令(linux中ls命令的用法)
- Linux lscpu 命令使用详解(linux常用ls命令)
- 如何查询 Linux 中 CPU 的数量?这几个命令要知道!
- 在linux上怎么查看cpu信息(linux如何查看cpu信息)
- 查看 CPU 的命令和磁盘 IO 的命令
- 如何在CentOS7上改变网卡名(centos怎么改网卡名字)
- 网工必备Linux网络管理命令(网工必备linux网络管理命令是什么)
- Linux 网络命令知多少(linux 网络 命令)
- Linux通过命令行连接wifi的方式(linux命令行连接无线网)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)