nginx - 访问 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 协议上提出的。
解决方案
推荐阅读
- kotlin - ReceiveAll() 在 Corda 中的应用是什么?如何实施?
- java - 在 Java 11 上使用 Jetty Maven 插件 9.4.32.v20200930 获取类“FutureCallback”和“LazyList”的“NoClassDefFoundError”
- sql - 获取使用排序溢出的 SQL 语句
- computer-vision - 使用工具、表单识别器、自定义标签进行标记后,两个字段的准确性较低
- excel - 在选定目录 msoFileDialogFolderPicker 上方拉一个目录
- android - 如何正确限制对 Android 和 iOS 应用程序(用 Flutter 编写)的 Google 地图(地点、地理编码)API 调用?
- xamarin - 如何使用绑定为 Xamarin 中的滑块提供某些颜色
- php - 简化嵌套 if 语句
- docker - 如何在 Docker 映像上执行完美流程?
- javascript - 如何修改脚本以删除第一列和第二列底部的行?