gzip_ratio不在nginx日志中打印

前端之家收集整理的这篇文章主要介绍了gzip_ratio不在nginx日志中打印前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在配置Nginx access_log以JSON格式输出以与其他工具一起使用.

我想要的数据包括有关压缩的信息.我有gzip,但我唯一得到的gzip_ratio是 – .

要确认,嵌入的var是$gzip_ratio.

http://nginx.org/en/docs/http/ngx_http_gzip_module.html

这是我的log_format的定义:

log_format  main_json '{"time": "$time_iso8601",'
                  '"remote_addr": "$remote_addr",'
                  '"body_bytes_sent": "$body_bytes_sent",'
                  '"gzip_ratio": "$gzip_ratio",'
                  '"status": "$status",'
                  '"request": "$request_time",'
                  '"request_method": "$request_method",'
                  '"http_referrer": "$http_referer",'
                  '"http_user_agent": "$http_user_agent",'
                  '"http_x_forwarded_for": "$http_x_forwarded_for",'
                  '"request_time": "$request_time",'
                  '"upstream_response_time": "$upstream_response_time"}';

以下是Nginx.conf中的gzip设置:

gzip  on;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript text/javascript application/xml+RSS text/json application/json;

这是access_log中的输出

{
    "time":"2015-02-03T14:26:26+00:00","remote_addr":"[IP]","body_bytes_sent":"574","gzip_ratio":"-","status":"200","request":"0.064","request_method":"GET","http_referrer":"-","http_user_agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/42.0.2293.0 Safari/537.36","http_x_forwarded_for":"-","request_time":"0.064","upstream_response_time":"0.064"
}

所以,事情似乎没有被压缩.但是,我运行cURL来测试压缩,结果如下:

[~]$curl https://[URL] --silent --write-out "size_download=%{size_download}\n" --output /dev/null
size_download=3297
[~]$ curl https://[URL] --silent -H "Accept-Encoding: gzip,deflate" --write-out "size_download=%{size_download}\n" --output /dev/null
size_download=859

因此,从实际测量响应的大小来看,它似乎正在被压缩.但是,日志仍然缺少gzip_ratio.每个请求的日志中的body_bytes_sent最多匹配cURL报告的字节(具有压缩响应的轻微变化).

{"time": "2015-02-03T14:57:11+00:00","remote_addr": "[IP]","body_bytes_sent": "3297","gzip_ratio": "-","status": "200","request": "0.477","request_method": "GET","http_referrer": "-","http_user_agent": "curl/7.37.0","http_x_forwarded_for": "-","request_time": "0.477","upstream_response_time": "0.477"}
{"time": "2015-02-03T14:57:20+00:00","body_bytes_sent": "871","request": "0.676","request_time": "0.676","upstream_response_time": "0.676"}

有谁知道我怎么能得到实际的gzip_ratio?

最佳答案
您使用的是Nginx错误版本,或者您的测试方法存在一些缺陷.我刚刚确认log_format定义中的$gzip_ratio在Nginx 1.9.1中运行得非常好.

我看到$gzip_ratio只相等 – 当没有执行压缩时.在所有其他情况下,它保持数值.

原文链接:https://www.f2er.com/nginx/435348.html

猜你在找的Nginx相关文章