nginx自定义log_format以及输出自定义http头
官方文档地址:
http://nginx.org/en/docs/http/ngx_http_log_module.html
一、log_format默认格式
首先Nginx默认的log_format的格式为:
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
上面的main标识给log_format取的别名,比如我可以首先定义多个log_format,例如下面的nginx.conf,我就定义了两个log_format,一个别名叫yuedu,一个别名叫default
http
{
include mime.types;
#include luawaf.conf; include proxy.conf; log_format yuedu '$http_yd_uid $http_yd_token $remote_addr [$time_local] $request_method $http_host $request_uri $status $body_bytes_sent $upstream_response_time "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
log_format default '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; default_type application/octet-stream;
......
include /www/server/panel/vhost/nginx/*.conf;
}
三、给web网站分配log_format
在nginx里面新建web站点的时候,可以配置该站点使用的log_format格式,如果不指定log_format,则使用的默认的log_format,如下面这个站点使用是别名为yuedu的log_format
access_log /www/wwwlogs/xxx.log yuedu;
server
{
listen 80; server_name www.xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/xxx; ......
access_log /www/wwwlogs/xxx.log yuedu;
error_log /www/wwwlogs/xxx.error.log;
}
四、access_log里打印自定义的消息header头
比如现在客户端在http请求里,加入一个新的自定义的header
Yd-Token : 123465
那么在log_format里要打印输出这个header,则只需要取变量$http_yd_token,则可以打印这个header了
log_format yuedu '$http_yd_token ...'
类似的如果要在log_format里打印 Xxx-Yyy这样的消息头,只需要使用$http_xxx_yyy即可
nginx自定义log_format以及输出自定义http头的更多相关文章
- 自定义 ocelot 中间件输出自定义错误信息
自定义 ocelot 中间件输出自定义错误信息 Intro ocelot 中默认的 Response 中间件在出错的时候只会设置 StatusCode 没有具体的信息,想要展示自己定义的错误信息的时候 ...
- asp.net mvc输出自定义404等错误页面,非302跳转。
朋友问到一个问题,如何输出自定义错误页面,不使用302跳转.当前页面地址不能改变. 还要执行一些代码等,生成一些错误信息,方便用户提交反馈. 500错误,mvc框架已经有现成解决方法: filters ...
- asp.net mvc输出自定义404等错误页面,非302跳转
朋友问到一个问题,如何输出自定义错误页面,不使用302跳转.当前页面地址不能改变. 还要执行一些代码等,生成一些错误信息,方便用户提交反馈. 500错误,mvc框架已经有现成解决方法: filte ...
- log4j2自定义Appender(输出到文件/RPC服务中)
1.背景 虽然log4j很强大,可以将日志输出到文件.DB.ES等.但是有时候确难免完全适合自己,此时我们就需要自定义Appender,使日志输出到指定的位置上. 本文,将通过两个例子说明自定义APP ...
- mfix输出自定义数据
有时候需要输出一些自定义的网格或者DEM颗粒信息,比如输出颗粒的受力,这里举例颗粒自定义数据的输出.网格自定义输出方法类似. 首先用FileLocatorPro(网上很多绿色版),搜索一下代码里mod ...
- 重新想象 Windows 8 Store Apps (26) - 选取器: 自定义文件选取窗口, 自定义文件保存窗口
原文:重新想象 Windows 8 Store Apps (26) - 选取器: 自定义文件选取窗口, 自定义文件保存窗口 [源码下载] 重新想象 Windows 8 Store Apps (26) ...
- 自定义EL函数、自定义JSTL标签
自定义EL函数 1.做一个类(静态) package com.maya.el; public class ELBiaoDaoShi { public static String TiHuan(Stri ...
- 10.自定义EL函数和自定义标签
需要在JSP页面中进行一些常见逻辑操作(如对字符串进行操作),首先考虑是否可以用到sun公司提供的EL函数库(fn.tld)和JSTL 核心标签库 如果sun公司的EL函数库没有或者无法满足,就需要自 ...
- [Python自学] day-21 (1) (请求信息、html模板继承与导入、自定义模板函数、自定义分页)
一.路由映射的参数 1.映射的一般使用 在app/urls.py中,我们定义URL与视图函数之间的映射: from django.contrib import admin from django.ur ...
随机推荐
- 一个轻量级的模态组件,“礼貌地”要求您的用户停止使用过时的IE浏览器
插件github地址:https://github.com/panteng/ie-blocker 我们在做项目时,会考虑到浏览器的兼容问题,当然做,全浏览器都支持的项目我还没经历过,也不想经历,目前做 ...
- jQuery属性操作之html属性操作
jQuery的属性操作, 是对html文档中的属性进行读取.设置和移除操作.比如,attr(). removeAttr(). 1. attr() attr()可以设置属性值或者返回被选元素的属性值 1 ...
- [svn]指定用户名
svn [option] --username=faith --passward=521 或者 svn [option] --username "faith" --passward ...
- 生产者和消费者之间的线程通讯wait()
生产者与消费者,采用notify()唤醒 package com.dwz.concurrency.chapter9; /** * 生产者和消费者之间的通信问题 * 执行wait()之后锁被释放 */ ...
- 在浏览器上打开、预览Excel xlsx表格文件
现在的HTML5,有了FileReader文件读写API, 真是让javascript的能力大幅提升. 解析zip压缩文件.解析Excel xlsx 表格文档各种文件预览,实现起来也有了可能性,以前的 ...
- Failed to execute goal maven-gpg-plugin 1.5 Sign
问题描述: 解决办法:跳过maven-gpg-plugin <build> <pluginManagement> <plugins> <plugin> ...
- CountDownLatch和CylicBarrier以及Semaphare你使用过吗
CountDownLatch 是什么 CountDownLatch的字面意思:倒计时 门栓 它的功能是:让一些线程阻塞直到另一些线程完成一系列操作后才唤醒. 它通过调用await方法让线程进入阻塞状态 ...
- ARTS打卡计划第七周
Algorithms: https://leetcode-cn.com/problems/longest-common-prefix/ Review: https://link.medium.com/ ...
- JAVA之G1与CMS垃圾回收
G1 GC,全称Garbage-FirstGarbage Collector,通过-XX:+UseG1GC参数来启用,作为体验版随着JDK 6u14版本面世,在JDK 7u4版本发行时被正式推出,相信 ...
- Qt高级——QTestLib单元测试框架
一.QTestLib简介 1.QTestLib简介 QTestLib是Qt提供的一种针对基于Qt编写的程序或库的单元测试框架.QTestLib提供了单元测试框架的基本功能,并提供了针对GUI测试的扩展 ...