nginx如何打印tcp请求日志
在nginx.conf配置文件中加入如下配置,可以将TCP请求日志打印到access.log文件中:
stream {
log_format tcp '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'$upstream_bytes_sent $upstream_bytes_received $upstream_connect_time';
access_log /var/log/nginx/access.log tcp;
server {
listen 80;
proxy_pass backend;
}
}
其中,“log_format tcp”定义了TCP请求日志的格式,“access_log”指定了日志输出的文件路径和格式。当请求到达nginx服务器时,日志信息将被记录到access.log文件中。
原文地址: https://www.cveoy.top/t/topic/dvKZ 著作权归作者所有。请勿转载和采集!