网站首页 > 技术教程 正文
日志功能在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 日志
欢迎 你 发表评论:
- 12-13360浏览器官网在线使用
- 12-13一键系统备份工具(一键系统备份软件)
- 12-132345浏览器影视大全(2345浏览器版本大全)
- 12-13office产品密钥在哪看(查看office产品密钥)
- 12-13电脑速度慢怎么清理(电脑很慢如何清理)
- 12-13w7激活工具免费下载(win7激活工具合集)
- 12-13鑫创u盘量产教程(鑫创sss6697量产教程)
- 12-13微信好友恢复破解版(微信好友恢复 破解版)
- 最近发表
- 标签列表
-
- 下划线是什么 (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)

本文暂时没有评论,来添加一个吧(●'◡'●)