nginx:[emerg] unknown" bytes_received"变量

时间:2018-04-03 11:09:59

标签: nginx

我尝试记录从Nginx中的客户端收到的字节数,如下所示:

log_format postdata '$remote_addr sent $bytes_received bytes';

但是,尝试启动服务时出现以下错误:

nginx: [emerg] unknown "bytes_received" variable

据我所知,这个变量应该来自Nginx 1.11.4。我跑1.13.9:

#:/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.13.9

nginx -V的输出:

:~# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.13.9
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-pcre --with-http_realip_module --with-stream --add-module=../nchan

我在这里缺少什么?

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

PS:使用答案作为发布大型文字所需的评论

好像你从源代码编译它并且缺少必需的模块。我在相同的

下面有输出
  

配置参数: - with-cc-opt =' -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror = format-security -Wdate-time -D_FORTIFY_SOURCE = 2' --with-ld-opt =' -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix = / usr / share / nginx --conf-path = / etc / nginx / nginx.conf --http-log-path = / var / log / nginx / access.log --error-log-path = /var/log/nginx/error.log --lock-path = / var / lock / nginx.lock --pid-path = / run / nginx.pid --http-client-body-temp-path = / var / lib / nginx / body --http-fastcgi-temp-path = / var / lib / nginx / fastcgi --http-proxy-temp-path = / var / lib / nginx / proxy --http-scgi-temp- path = / var / lib / nginx / scgi --http-uwsgi-temp-path = / var / lib / nginx / uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_auth_request_module --with-http_auth_request_module --with-http_adav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

因此,请确保至少拥有所有stream模块,并且可能是其他模块是此工作的先决条件

答案 1 :(得分:0)

$request_length 可能就是您想要的:

<块引用>

请求长度(包括请求行、头部和请求体)

如果您使用的是没有内置 ngx_stream_core_module 的 Nginx,这会记录从客户端收到的请求的大小,而不会遇到未知变量问题。

换句话说,$request_length(而不是 $bytes_received)似乎是 $bytes_sent 的对应物,有点令人困惑。