首页 > 解决方案 > 访问 nginx 流代理没有记录在 access_log 文件中

问题描述

感谢您检查我的问题。

我正在尝试将用户访问从浏览器记录到现在不工作的 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 显示代理服务器的 ip in Headers tab > General > Remote Address field. 我从我的笔记本电脑上检查了 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_log 配置,但是当我从笔记本电脑卷曲相同的 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 协议上提出的。

标签: nginxproxynginx-reverse-proxynginx-configaccess-log

解决方案



推荐阅读