Nginx prints the header parameter information of all requests (http/https) in the access.log log
Combining the articles of the following two bloggers is a complete solution. I would like to express my gratitude here. I will sort it out and make relevant explanations.
https://www.cnblogs.com/befer/p/10074141.html
https://www.cnblogs.com/xiaodebing/p/9399440.html
》Step1: Install LuaJIT on CentOS7.7
lua (www.lua.org) is a scripting language developed for embedding into other applications, and luajit (www.luajit.org) is lua Just-In-Time translation for runtime compilation. nginx obtains request header parameters using the functions provided by LuaJIT.
1. Install 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
#Import two environment variables
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
2. Download ngx_devel_kit, and 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. Enter the nginx source data directory and recompile 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
Add a new /usr/local/luajit/lib
Save the file and execute ldconfig.
》Step2: Modify the configuration of nginx.conf
1. Customize the log format of access.log in http{}
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. Obtain http request header and return header
3. Obtain https request header and return header