首页 > 系统相关 >nginx配置log_format

nginx配置log_format

时间:2023-09-13 10:01:39浏览次数:30  
标签:http log format request nginx user time

1. 默认格式:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

(1). 参数说明:

|参数|说明| |---|---|---| |nginx配置log_format_Nginxremote_user | 客户端用户名称 | -- |nginx配置log_format_客户端_02request | 请求的URI和HTTP协议 | "GET /article-10000.html HTTP/1.1" |nginx配置log_format_客户端_03body_bytes_sent | 发送给客户端文件内容大小 | 1547 |nginx配置log_format_Nginx_04http_user_agent | 用户终端浏览器等信息 | "Mozilla/4.0 ... |$request_time | 整个请求的总时间 | 0.205

2. 自定义log_format:

(1). 自定义log_format:

vim /etc/nginx/nginx.conf
http
{
    ...

    log_format request '$remote_addr - $remote_user [$time_local] "$request"'
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for" $request_time';

    ...
}

(2). 给web网站分配log_format:

server
{
    ...
    access_log  /etc/logs/xxx.log request;
    error_log  /etc/logs/xxx.error.log;
    # 不指定log_format,则使用的默认的log_format.
}

(3). 两个时间的疑问?

  • $request_time: a. request processing time in seconds with a milliseconds resolution(1.3.9, 1.2.6);time elapsed since the first bytes were read from the client. b. 这个时间是从Nginx接收到客户端第一个字节的数据开始计时的,包含了接收数据、等待响应的时间.
  • $upstream_response_time: a. keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable. b. 这个时间是Nginx等待后端程序响应的时间.

标签:http,log,format,request,nginx,user,time
From: https://blog.51cto.com/u_16251183/7451963

相关文章

  • nginx之模块
    模块概述nginx将各功能模块组织成一条链,当有请求到达的时候,请求依次经过这条链上的部分或者全部模块,进行处理。每个模块实现特定的功能。例如,实现对请求解压缩的模块,实现SSI的模块,实现与上游服务器进行通讯的模块,实现与FastCGI服务进行通讯的模块。有两个模块比较特殊,他们居于n......
  • 安装Nginx
    一、使用CentOS7自带Yum安装Nginx1、在安装Nginx前,先执行以下命令更新Yum源:yumupdate2、使用以下命令安装Nginx:yuminstallnginx3、安装完成后,使用以下命令启动Nginx:systemctlstartnginx二、手动编译安装Nginx1、下载Nginx源码包:wgethttp://nginx.org/download/ngin......
  • WebRTC rtc::FileRotatingLogSink日志使用
    前言WebRTC默认日志打印到控制台,如果需要打印到文件或网络,需要自己继承并实现LogSink这个类的接口。即在OnLogMessage函数里面完成日志的输出(写磁盘文件,写网络socket等)。庆幸的是webrtc中的FileRotatingLogSink类帮助我们实现日志写入磁盘文件,并且FileRotatingLogSink能控制文件......
  • 通过Nginx配置一个ftp目录下载
    1首先需要安装Nginx组件2指定下载展示的目录,证书地址,日志信息位置即可。server{listen443ssl;server_namedownload.tianshiemo.com;ssl_certificate/ssl/download/fullchain.crt;ssl_certificate_key/ssl/download/private.key;access_log/cod......
  • glog 日志库简介与测试【GO 常用的库】
    〇、前言golang/glog是C++版本google/glog的Go版本实现,基本实现了原生glog的日志格式。在Kuberntes中,glog是默认日志库。因此需要详细了解下。下面列举下glog的特点:高效性:glog采用了异步写入日志的方式,这意味着日志记录操作不会阻塞主程序的执行。它还使用了缓......
  • nginx https 403错误
    userwwwwww;worker_processesauto;worker_cpu_affinityauto;error_log/home/wwwlogs/nginx_error.logcrit;pid/usr/local/nginx/logs/nginx.pid;#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.worker_rlimit_no......
  • logback日志压缩配置
     <configuration><!--RollingFileAppender继承自FileAppender,具有轮转日志文件的功能,是我们最常使用的Appender--><appendername="ROLLING"class="ch.qos.logback.core.rolling.RollingFileAppender"><!--支持多个JVM同时写一个文件......
  • 十、Nginx防盗链设计
    先了解一下何谓盗链:「「盗链即是指外部网站引入当前网站的资源对外展示」」 ,来举个简单的例子理解:❝好比壁纸网站X站、Y站,X站是一点点去购买版权、签约作者的方式,从而积累了海量的壁纸素材,但Y站由于资金等各方面的原因,就直接通过<imgsrc="X站/xxx.jpg"/>这种方式照搬了X站的所有......
  • 十一、Nginx大文件传输配置
    某些业务场景中需要传输一些大文件,但大文件传输时往往都会会出现一些Bug,比如文件超出限制、文件传输过程中请求超时等,那么此时就可以在Nginx稍微做一些配置,先来了解一些关于大文件传输时可能会用的配置项:在传输大文件时,client_max_body_size、client_header_timeout、proxy_read_ti......
  • 十二、Nginx配置SSL证书
    随着越来越多的网站接入HTTPS,因此Nginx中仅配置HTTP还不够,往往还需要监听443端口的请求,HTTPS为了确保通信安全,所以服务端需配置对应的数字证书,当项目使用Nginx作为网关时,那么证书在Nginx中也需要配置,接下来简单聊一下关于SSL证书配置过程:①先去CA机构或从云控制台中申请对应的SSL证......