当前位置: 首页 > article >正文

nginx accesslog 打印自定义header

比如我在请求的header中添加了一个path-match-type,那我现在nginx的accesslog 中打印出来,应该如何配置呢?

root@nginx-59f5d66df6-jw5k8:/# cat /etc/nginx/nginx.conf 

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

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

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

==>
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

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

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

注意两点

  • 自定义header时候,header的name不能包含下划线(_)
  • 在nginx access log日志格式配置的时候,需要将header的name中的中划线改成下划线并添加http_开头,比如本文中path-match-type ==>$http_path_match_type

http://www.kler.cn/a/571574.html

相关文章:

  • 北京航空航天大学计算机复试上机真题
  • 快速高效使用——阿里通义万相2.1的文生图、文生视频功能
  • intra-mart实现logicDesigner与forma联动
  • 第52天:Web开发-JavaEE应用SpringBoot栈SnakeYaml反序列化链JARWAR构建打包
  • 【由技及道】API契约的量子折叠术:Swagger Starter模块的十一维封装哲学【人工智障AI2077的开发日志】
  • 关联封号率降70%!2025最新IP隔离方案实操手册
  • android::IPCThreadState::self使用介绍
  • ASP.NET MVC项目部署到IIS后,w3wp.exe程序报错重启
  • CSS—flex布局、过渡transition属性、2D转换transform属性、3D转换transform属性
  • Python的那些事第三十九篇:MongoDB的Python驱动程序PyMongo
  • 解决android studio(ladybug版本) gradle的一些task突然消失了
  • B3DM转换成PLY
  • 深度探索:美团开源DeepSeek R1 INT8量化技术的性能革命
  • slf4j和log4j的区别与使用
  • linux ubuntu系统运行python虚拟环境,启用端口服务和定时任务
  • 解锁MacOS开发:环境配置与应用开发全攻略
  • 算法--贪心
  • [绘图机器]
  • 2024四川大学计算机考研复试上机真题
  • 使用R包ellmer接入Deepseek