nginx日志格式配置
我一向对日志这个东西有些许恐惧,因为在分析日志是需要记住不同服务器日志的格式,就拿提取ip这一项来说,有的服务器日志是在第一列,有的是第二列或则第三列等等。知道今天我才发现,日志格式是可以自定义配置的。。。。
现在我们来看一下nginx的日志格式如何自定义配置
log_format指令用来设置日志格式,其语法如下:
log_format name format [format …]
nginx默认日志格式具体参数如下:
log_format combined '$remote_addr - $remote_user [$time_local]'
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
看一下一条nginx日志
192.168.3.113 - - [23/Jul/2017:01:17:43 -0700] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
可以看到分别对应的是ip 远程用户名 时间 请求 请求状态 以及用户客户端信息等等
那么日志配置是在哪里进行配置的呢
[root@localhost nginx]# !446
cat conf/nginx.conf|grep -v "#"|grep -v "^$"
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format mylog '$remote_addr [$time_local]' '"$http_user_agent"'; #在这里进行配置,命名为mylog,也可以把这条语句放在server里面
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.bp1.com;
location / {
root html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server{
listen 192.168.3.123:80;
server_name www.bp3.com;
access_log logs/bp2.access.log mylog; #使用刚配置的日志文件格式mylog
location /
{
index index.html index.php;
root html/bp2;
}
location ~ \.php$ {
root html/bp2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server{
listen 192.168.3.125:80;
server_name www.bp2.com;
location /{
root html/bp3;
index index.html index.php;
}
location ~ \.php$ {
root html/bp3;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@localhost nginx]#
效果
192.168.3.113 [23/Jul/2017:01:37:51 -0700]"Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
nginx日志格式配置的更多相关文章
- Nginx 日志格式配置介绍
Nginx日志格式配置介绍 by:授客 QQ:1033553122 测试环境 CentOS 6.5-x86_64 nginx-1.10.0 配置例子 log_format main '$ ...
- 运维技巧-Nginx日志格式
1.说一说 当你安装完nginx,输出的格式是比较乱的,这样我们就需要自己去定义一下,自己看着舒服的格式. 2.Nginx日志字段 $remote_addr 记录客户端IP,但她的值不是客户端提供的, ...
- Nginx日志格式以及相关配置
一.Nginx日志格式以及参数说明log_format main '$remote_addr - $remote_user [$time_local] "$request" ' ...
- Nginx日志文件配置与切割
Nginx日志的指令主要有两条: log_format,设置日志的格式 access_log,指定日志文件的存放路径.格式和缓存大小 两条指令在Nginx配置文件中的位置可以在http{……..}之间 ...
- ELK 之三:Kibana 使用与Tomcat、Nginx 日志格式处理
一:kibana安装: kibana主要是搜索elasticsearch的数据,并进行数据可视化的展现,新版使用nodejs. 1.下载地址: https://www.elastic.co/downl ...
- nginx日志 logrotate配置
nginx 日志 logrotate配置如下: /var/log/nginx/*.log { daily missingok rotate 20 compress delaycompress noti ...
- Nginx - 日志格式及输出
1. 前言 在 Nginx 服务器中,如果想对日志输出进行控制还是很容易的.Nginx 服务器提供了一个 HttpLogModule 模块,可以通过它来设置日志的输出格式. 2. HttpLogMod ...
- nginx日志输出配置json格式
修改nginx配置文件 http { include mime.types; default_type application/octet-stream; charset utf-8; # 原有日志格 ...
- nginx日志格式字段
Nginx日志主要分为两种:访问日志和错误日志.日志开关在Nginx配置文件(/etc/nginx/nginx.conf)中设置,两种日志都可以选择性关闭,默认都是打开的. 访问日志 访问日志主要记录 ...
随机推荐
- MYSQL基础知识小盲区
MYSQL必会的知识 命令行 启动mysql: mysql -u用户名 -p密码 显示表中的各列详细信息: show columns form tablename 等价于 desc ...
- C++构造函数和析构函数,以及构造函数特殊成员变量和函数的初始化
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- webView 的种种
1.关于UI 我们在设置webview的时候,有时候会发现在加载的过程中会出现一个黑色的条条,在加载完成的时候有得时候继续存在,有得时候消失不见. 这个黑边是由于webView.scrollview向 ...
- SecureCRT使用(转)
功能介绍 连接概述 1.当您启动SecureCRT时,您将看到“快速连接”对话框与主SecureCRT窗口一起出现. 2.有几种接口可用于连接远程机器:快速连接对话框,工具栏上的连接栏,会 ...
- 7系列FPGA远程更新方案-QuickBoot(转)
reference: http://xilinx.eetrend.com/d6-xilinx/article/2014-04/7009.html reference : quickboot meth ...
- http 性能测试. Apache ab 使用.
参数: 1. ab -n 100 -c 10 地址: 请求100次, 并发10次. 2. ab -n 100 -c 10 -w 地址: 请求100次, 并发10次 ,html 表 ...
- 【转】Delphi XE10 Android Splash设备自适应和沉浸式状态条
再次提笔写博客,已经相隔7年,原来的CSDN账号需要手机验证,而我的手机又捆绑到这个账号了,就用新账号吧,不想折腾了. 原账号的帖子,有研究DICOM3.0的可以看下:http://blog.csdn ...
- CentOS部署PHP环境
1.安装apache yum -y install httpd httpd-devel 2.启动apache systemctl start httpd.service 检查apache状态 syst ...
- mysql主从复制-读写分离-原理
Mysql主从复制和读写分离 在实际的生产环境中,如果对mysql数据库的读和写都在一台数据库服务器中操作,无论是在安全性.高可用性,还是高并发等各个方面都是不能满足实际需求的.因此,一般通过主从复制 ...
- pycharm 永久解封
第一步 c:\windows\system32\drivers\etc 命令行输入这个 第二步 把host文件复制到桌面 第三步 记事本打开host 第四步 在最下面添加 ...