access_log 文件中未记录对 nginx 流代理的访问

问题描述

感谢您检查我的问题。

我正在尝试将来自浏览器的用户访问记录到现在不起作用的 access_log 文件中。

我的系统:

[用户]-[TCP 代理]-[网络服务器]

AWS EC2 中的 nginx/1.6

nginx 配置:

load_module '/usr/lib64/nginx/modules/ngx_stream_module.so';
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

stream {
    log_format basic '$remote_addr [$time_local] '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time';
    access_log /var/log/nginx/access.log basic;

    server {
        listen 80;
        proxy_pass web.server.com:80;
    }

    server {
        listen 443;
        proxy_pass web.server.com:443;
    }
}

我通过 Chrome 的代理服务器从本地笔记本电脑打开了该网站,它打开良好,chrome devtool 在 Headers tab > General > Remote Address field 中显示了代理服务器的 ip。 我检查了我的笔记本电脑上的 dig,它显示了代理服务器的 IP, 甚至代理服务器中的 tcpdump 也显示出良好的日志:sudo tcpdump -nn -A -s1500 -l -i eth0 port 443

(from tcpdump)
23:51:46.944945 IP user_ip.27149 > proxy_ip: length 357
23:51:46.945040 IP proxy_ip.44488 > webserver_ip.443: length 357
23:51:47.026161 IP webserver_ip.443 > proxy_ip.44488: length 364
23:51:47.026245 IP proxy_ip.443 > user_ip.27149: length 364 

但是当我在代理服务器中打开访问日志文件时,没有任何条目。

与 stackoverflow Nginx access logs entries don't get created for some connections when they happen 中的类似问题不同,没有初始条目。只是空的。

我一开始怀疑是 access_log 配置,但是当我从笔记本电脑中 curl 相同的 url 时,条目突然出现在 access_log 文件中。每次我卷曲网址时它都会出现。

user_ip [15/Feb/2021:23:21:25 +0000] TCP 200 1291080 3279 356.730
user_ip [15/Feb/2021:23:28:24 +0000] TCP 200 215 568 119.923
user_ip [15/Feb/2021:23:33:24 +0000] TCP 200 5646 643 300.140

我不确定为什么只有 curl 请求被记录到 access_log 文件中。 ?

所有请求都是在 https 协议上进行的。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)