nginx启用TCP反向代理日志配置
Nginx使用TCP反向代理日志配置不同于http
修改nginx配置文档/usr/local/nginx/conf/nginx.conf 设置日志格式
stream { log_format proxy '$remote_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received ' '$session_time "$upstream_addr" ' '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"'; include ./conf.d/*.conf; }
修改具体的tcp配置文档conf.d/*.conf
upstream 443 { 1.1.1.1:443 } server{ error_log /var/log/443_error.log; access_log /var/log/443_access.log proxy; listen 5001; proxy_pass 443; }
重载nginx
nginx -s reload
查看
•测试发现nginx会等待session结束才会记录到日志文件;
•session日志只是tcp层面的记录,包括session时间,发送接收字节数等等;
•session内部发送日志(比如一个socket连接建立起来以后,多次发送心跳数据)需要在应用层面才能记录;