网站首页 > 博客文章 正文
日志功能在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都问哪些问题呢?
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- 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)
本文暂时没有评论,来添加一个吧(●'◡'●)