Reputation: 2478
I try to log the amount of bytes received from a client in Nginx like so:
log_format postdata '$remote_addr sent $bytes_received bytes';
However, I get the following error when attempting to start the service:
nginx: [emerg] unknown "bytes_received" variable
As far as I can see this variable should be present from Nginx 1.11.4. I run 1.13.9:
#:/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.13.9
Output of 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
Is there something I am missing here?
Thanks for any help!
Upvotes: 1
Views: 2013
Reputation: 2968
$request_length
may be what you want:
request length (including request line, header, and request body)
This logs the size of the request received from the client without hitting the unknown variable issue, if you're using a build of Nginx which doesn't have ngx_stream_core_module
built in.
In other words $request_length
(rather than $bytes_received
) seems to be the counterpart to $bytes_sent
, somewhat confusingly.
Upvotes: 0
Reputation: 146510
PS: Using answers as comments as I need to post large text
Seems like you have it compiled from source and a required module is missing. I have below output on the same
configure arguments: --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_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_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
So make sure you have all the stream
modules at least and may be some other module is a pre-requisite for this to work
Upvotes: 1