日志格式使用指令

指令介绍
Syntax: log_format name [escape=default|json|none] string ...;
Default: log_format combined "...";
Context: http 默认的日志文件
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent ' '"$http_referer"
"$http_user_agent"';

  日志文件路径定义

Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;
Default: access_log logs/access.log combined;
Context: http, server, location, if in location, limit_except
路径可包含变量,不打开日志缓存时,每记录一条日志都需要打开关闭日志文件
if 通过变量值来判断日志是否记录
日志缓存:
功能:批量将内存日志写入文件中
写入磁盘的条件:所有待写入磁盘日志文件大小超出缓存大写;达到flush指定的过期时间;worker进程执行reopen命令,或正在关闭
日志压缩:批量压缩内存中日志,再写入磁盘。buffer默认大小为64kb;压缩级别默认为1(1最快压缩率最低,9最快压缩来较高)

  对日志文件包含的变量名优化

指令

Syntax: open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
Default: open_log_file_cache off;
Context: http, server, location max:缓存内的最大文件句柄数;超出后用LRU算法淘汰
inactive:文件访问完在这段时间不会被关闭默认10秒
min_uses:在inactive时间内使用的次数超过min_uses才会继续保存在内存,默认1
valid:超出这个时间后,会检查缓存日志文件是否存在,默认60秒
off:关闭缓存功能

  过滤模块工作位置

默认sub_module未编译进nginx

启用此模块

[root@python nginx-1.15.9]#  ./configure --prefix=/data/web --sbin-path=/usr/bin --user=nginx --group=nginx --with-http_stub_status_module --with-http_auth_request_module --with-http_sub_module --add-module=/root/nginx-http-concat
[root@python nginx-1.15.9]# make
[root@python nginx-1.15.9]# mv /usr/bin/nginx{,.07.12.13.18}
[root@python nginx-1.15.9]# cp objs/nginx /usr/bin/

  更改响应中的字符串

sub模块指令
Syntax: sub_filter string replacement; #把匹配上的返回给用户响应中的字符串替换replacement指定的字符串
Default: —
Context: http, server, location
Syntax: sub_filter_last_modified on | off;# 是否还返回给用户未修改的内容呢;默认不会再返回了
Default: sub_filter_last_modified off;
Context: http, server, location
Syntax: sub_filter_once on | off; # 是否只替换一次,如果关闭会返回所有的响应报文的boyd内容都做替换
Default: sub_filter_once on;
Context: http, server, location
Syntax: sub_filter_types mime-type ...; # 只对什么类型文件的响应做替换
Default: sub_filter_types text/html;
Context: http, server, location

  配置

server {
server_name www.chenxi.com sub.com;
access_log logs/sub.log main;
root html;
index index.html index.htm;
location / {
#sub_filter 'Nginx.oRg' '$host/nginx';
#sub_filter 'nginX.cOm' '$host/nginx';
#sub_filter_once on;
#sub_filter_once off;
#sub_filter_last_modified off;
#sub_filter_last_modified on;
}
}

  在浏览器测试

修改配置打开替换的内容

[root@python vhast]# cat sub.conf
server {
server_name www.chenxi.com sub.com;
access_log logs/sub.log main;
root html;
index index.html index.htm;
location / {
sub_filter 'Nginx.oRg' '$host/nginx';
sub_filter 'nginX.cOm' '$host/nginx';
#sub_filter_once on;
#sub_filter_once off;
sub_filter_last_modified off;#只替换一次
#sub_filter_last_modified on;
}
}

  测试

修改配置

server {
server_name www.chenxi.com sub.com;
access_log logs/sub.log main;
root html;
index index.html index.htm;
location / {
sub_filter 'Nginx.oRg' '$host/nginx';
sub_filter 'nginX.cOm' '$host/nginx';
#sub_filter_once on;
sub_filter_once off;
#sub_filter_last_modified off;
sub_filter_last_modified on;
}
}

  测试

最新文章

  1. HTML5_02之视频、音频、Canvas
  2. redisTemplate的spring配置以及lua脚本驱动
  3. 修改applicationhost.config允许外部访问
  4. JavaScript设计模式——状态模式
  5. [问题2014A01] 复旦高等代数 I(14级)每周一题(第三教学周)
  6. Oracle Insert 多行(转)
  7. jQuery循环滚动新闻列表
  8. Cocos2d-JS中的精灵菜单和图片菜单
  9. C#中的值类型(value type)与引用类型(reference type)的区别
  10. 关于xml作为模板的配置服务系统开发
  11. JavaWeb限流QPS简易框架
  12. struts2_20140720
  13. 【Time系列三】简单的计时器(秒表)
  14. 上海赛区-org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters.
  15. 绕过校园网WEB认证_iodine实现
  16. Flask实战-留言板-使用Flask-DebugToolbar调试程序、Flask配置的两种组织形式
  17. 找到多个与名为“Home”的控制器匹配的类型
  18. Python3列表(list)比较操作教程
  19. vue使用方法计算总金额
  20. Eclipse启动tomcat后404错误

热门文章

  1. Nexus坑人系列-license格式问题
  2. mybatis--MyBatis动态SQL语句
  3. 【C语言】用函数实现两个数排序(指针作函数参数)
  4. 妙用python之编码转换
  5. python学习之matplotlib绘制动图(FuncAnimation()参数)
  6. 一周搞定模拟电路P3_电容_记录
  7. websocket对象及方法
  8. TCP协议下的服务端并发,GIL全局解释器锁,死锁,信号量,event事件,线程q
  9. SpringBoot-自动装载
  10. <位运算> 任意二进制数 异或两个相同的二进制数 还是原本的值