【问题标题】:Access to nginx stream proxy is not logged in access_log file访问 nginx 流代理没有记录在 access_log 文件中
【发布时间】:2021-02-17 10:32:53
【问题描述】:

感谢您检查我的问题。

我正在尝试将用户从浏览器的访问记录到现在不工作的 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 配置,但是当我从笔记本电脑卷曲相同的 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 协议上发出的。

【问题讨论】:

  • 你试过不同的文件吗?也许对同一个文件的两个作者不满意。
  • @AllanWind l 将 access.log 文件名更改为 access1.log 为 80,access2.log 为 433,将每个 access_log 设置放入每个服务器块然后退休。但是我仍然无法从两个文件中找到来自 chrome 的访问日志。 ???谢谢你的想法。
  • 这不能回答您的问题,但工作配置可能是向前迈出的一步 stackoverflow.com/questions/42083611/…。如果创建了新的访问日志,则排除了权限,否则您可以尝试使用access_log syslog:unix:/dev/log 登录到系统日志。最后,我的建议是将此问题移至 serverfault,因为它不是编程问题。
  • @AllanWind 我明白了。感谢您的提示。让我试试。我也会将此问题移至 serverfault。

标签: nginx proxy nginx-reverse-proxy nginx-config access-log


【解决方案1】:
猜你喜欢
  • 2012-04-12
  • 1970-01-01
  • 2018-04-11
  • 2019-04-28
  • 2019-08-19
  • 2023-03-12
  • 2011-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多