nginx的日志管理


log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; main # 日志格式的名字
$remote_addr # 访问主机的ip
$remote_user # 访问用户的凭证,网页没有设置就没有。
$time_local # 服务器本地时间
$request # 请求和http版本
$status # 请求的状态码
$body_bytes_sent # 服务器返回的大小
$http_referer # 这个请求是从那个网站访问过来的
$http_user_agent # 能看到客户端的浏览器和操作系统信息
$http_x_forwarded_for # 源客户端IP,经过代理访问,记录原来的IP地址

日志的调用


在写好日志格式和取好名称之后直接使用下面方式调用。

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; log_format zidingyi '访问的IP:$remote_addr - 认证的用户:$remote_user - 访问的时间:[$time_local] - 请求
的资源:$request - 状态码:$status - 发送数据量:$body_bytes_sent - http_refere:"$http_referer"'; # access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/zidingyi_access.log zidingyi;

局部的调用方式。

[root@web01 /etc/nginx]# vi nginx.conf
............
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; log_format zidingyi '访问的IP:$remote_addr - 认证的用户:$remote_user - 访问的时间:[$time_local] - 请求
的资源:$request - 状态码:$status - 发送数据量:$body_bytes_sent - http_refere:"$http_referer"';
access_log /var/log/nginx/access.log main; ................
# =================================================================#
[root@web01 /etc/nginx/conf.d]# vi web01.conf
server {
listen 80;
server_name 10.0.0.7; location / {
root /code/web01;
index index.html;
}
access_log /var/log/nginx/web01_access.log zidingyi;
}

日志的路径


用指定路径会在指定的目录下生成日志文件。

# 这种配置方法会在指定目录下生成日志。/code/
[root@web01 /etc/nginx]# vi conf.d/web01.conf
server {
listen 80;
server_name 10.0.0.7; location / {
root /code/web01;
index index.html;
}
access_log /code/web01_zi_access.log main;
} # 会找到/etc/nginx下的log目录再存储日志。如果没有需要新建目录。
[root@web01 /etc/nginx]# vi conf.d/web01.conf
server {
listen 80;
server_name 10.0.0.7; location / {
root /code/web01;
index index.html;
}
access_log log/web01_zi_access.log main;
}
FBI WARNING

QQ:1402122292 认准原创sheldon 别人叫我晓东

最新文章

  1. Activity详解三 启动activity并返回结果
  2. 文本溢出省略解决笔记css
  3. html 实体转换为字符:转换 UEditor 编辑器 ( 在 ThinkPHP 3.2.2 中 ) 保存的数据
  4. Activity(一)
  5. 刷机(手机自带的recovery)
  6. Android中的自定义属性的实现
  7. BZOJ 2754([SCOI2012]喵喵叫的星球-统计序列的后缀阵列中子序列出现次数)
  8. Linux服务器集群技术的概述
  9. 编译安装apache2.4
  10. 表现层及ASP.NET MVC介绍(一)
  11. tomcat Server.xml Context配置问题
  12. 理解AngularJS中的依赖注入
  13. 安装IDEA的历程
  14. bootstrap-wysiwyg这个坑
  15. VS2017创建类库项目后添加不了WPF资源字典
  16. SharePoint 2013 地址栏_layouts/15/start.aspx#
  17. leetcode 之 Degree of an Array
  18. UI(三)
  19. PyQt4日历部件QXalendarWidget
  20. linux下ffmpeg安装(转)

热门文章

  1. Java刷题-tree
  2. Axure常用操作备忘
  3. Mariadb3—多表查询
  4. (一)LDAP 简介
  5. MinIO分布式集群的扩展方案及实现
  6. 记一次 .NET WPF布草管理系统 挂死分析
  7. Redis 与 Python 交互
  8. 记canvas画笔笔迹的多次优化过程
  9. 【Nginx(三)】Nginx配置集群 负载均衡策略
  10. hdu4685 最大匹配可能性