网站首页 > 博客文章 正文
日志功能在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入门——预定义变量和自定义变量(五)》。
- 上一篇: nginx配置http和tcp服务负载均衡
- 下一篇: Nginx搭建RTMP推拉流服务器
猜你喜欢
- 2024-12-19 nginx配置tcp代理
- 2024-12-19 Prometheus快速监控Nginx
- 2024-12-19 Nginx搭建RTMP推拉流服务器
- 2024-12-19 nginx配置http和tcp服务负载均衡
- 2024-12-19 解决php因为输出内容太短无法流式(Stream)输出问题
- 2024-12-19 利用Nginx正向代理实现局域网电脑访问外网
- 2024-12-19 使用 Nginx 实现推流搭建自己的流媒体服务器
- 2024-12-19 Nginx模块开发:从源码剖析整个Nginx框架
- 2024-12-19 Linux下如何用nginx+ffmpeg搭建流媒体服务器
- 2024-12-19 Linux运维面试nginx都问哪些问题呢?
你 发表评论:
欢迎- 366℃用AI Agent治理微服务的复杂性问题|QCon
- 358℃初次使用IntelliJ IDEA新建Maven项目
- 354℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 351℃Maven技术方案最全手册(mavena)
- 348℃安利Touch Bar 专属应用,让闲置的Touch Bar活跃起来!
- 346℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 344℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 342℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)