Nginx打印所有请求的头参数

Nginx在access.log日志中打印所有请求(http/https)的头部参数信息

将以下两位博主的文章合并一下就是完整的解决方案,在此表示感谢,我再梳理一下并做相关说明

https://www.cnblogs.com/befer/p/10074141.html

https://www.cnblogs.com/xiaodebing/p/9399440.html

》Step1:CentOS7.7安装LuaJIT

lua(www.lua.org)是为了嵌入其它应用程序而开发的一个脚本语言,luajit(www.luajit.org)是lua Just-In-Time译为运行时编译。nginx获取请求头参数就是使用LuaJIT提供的功能实现的。

1、安装LuaJIT

wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

tar -zxvf LuaJIT-2.0.5.gz && cd LuaJIT-2.0.5

make && make install PREFIX=/usr/local/luajit

#导入两个环境变量

export LUAJIT_LIB=/usr/local/luajit/lib

export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

2、下载ngx_devel_kit、和lua-nginx-module

wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1rc1.tar.gz

tar -xzvf ngx_devel_kit-0.3.1rc1.tar.gz

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14rc3.tar.gz

tar -xzvf v0.10.14rc3.tar.gz

3、进入nginx源数据目录,重新编译nginx

./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-threads –with-stream –add-module=/root/nginx_modules/lua-nginx-module-0.10.14rc3 –add-module=/root/nginx_modules/ngx_devel_kit-0.3.1rc1

make

[root@sjjy03 nginx-1.16.1]# cp objs/nginx /usr/local/nginx/sbin/

[root@gp-master sbin]# ./nginx

./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

vi /etc/ld.so.conf

新增一条 /usr/local/luajit/lib

保存文件,执行ldconfig ,即可。

 

》Step2:修改nginx.conf的配置

1、在http{}中自定义access.log的日志格式

log_format log_req_resp ‘$remote_addr – $remote_user [$time_local] “$request”  $status $body_bytes_sent “$http_referer” “$http_user_agent” $request_time ‘

 ‘req_header:”$req_header” resp_header:”$resp_header” – $server_name – $server_port – $server_protocol ‘;

2、获取http请求头与返回头

《Nginx打印所有请求的头参数》

3、获取https请求头与返回头

《Nginx打印所有请求的头参数》

 

    原文作者:运维小工
    原文地址: https://blog.csdn.net/Wemesun/article/details/117249531
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞