如何在nginx访问时获取请求参数

时间:2017-11-22 10:29:54

标签: json nginx

我们希望 access.log 上的请求数能够点击Web服务器。 目前,在我们的nginx.conf文件中,我们将日志格式转换为JSON并在服务器部分添加了存根状态以获取更多信息。 HTTP部分日志记录设置和服务器块的配置如下所示:

log_format  json  '{'
                    '"remote_addr": "$remote_addr",'
                    '"remote_user": "$remote_user",'
                    '"timestamp": "$time_iso8601",'
                    '"request": "$request",'
                    '"status": "$status",'
                    '"request_time": "$request_time",'
                    '"body_bytes_sent": "$body_bytes_sent",'
                    '"http_referer": "$http_referer",'
                    '"http_user_agent": "$http_user_agent",'
                    '"http_x_forwarded_for": "$http_x_forwarded_for",'
                    '"upstream_response_time": "$upstream_response_time",'
                    '"connection":"$connection",'
                    '"connection_requests": "$connection_requests",'
                    '"connections_active": "$connections_active",'
                    '"connections_reading": "$connections_reading",'
                    '"connections_writing": "$connections_writing",'
                    '"connections_waiting": "$connections_waiting"'
                    '}';

access_log /var/log/nginx/access.log json;
error_log /var/log/nginx/error.log;

我们在服务器部分添加了stub_status,如:

server {
    location /nginx_status {
        stub_status on;

        access_log on;
        allow 127.0.0.1;
        deny all;
    }
}

通过更改为此配置,我们将以json格式获取日志。 下面我们将展示access.log:

  

{" remote_addr":" xx.x.xx.xxx"," remote_user":" - ",&#34 ;时间戳&#34 ;:   " 2017-11-22T10:09:36 + 00:00","请求":" GET   /static/images/favicon.ico?v=2 HTTP / 1.1"," status":   " 200"," request_time":" 0.000"," body_bytes_sent":   " 2366"," http_referer":" - "," http_user_agent":" Mozilla / 5.0(X11; Linux   x86_64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 49.0.2623.75   Safari / 537.36 Google Favicon"," http_x_forwarded_for":   " xxx.xxx.x.xx"" upstream_response_time&#34 ;:   " - ""连接":" 44827"" connection_requests&#34 ;:   " 1"," connections_active":" 2"," connections_reading":   " 0"," connections_writing":" 0"," connections_waiting":" 1"}

现在问题是,我们有$connection_requests,我们得到每个连接的请求。但是,我们需要访问服务器的请求数量 是否有任何参数或变量可以返回请求数量? 如果没有参数,您能帮助我们找到获得这些请求数量的方法吗?

谢谢...

0 个答案:

没有答案