How to Configure JSON Log Format for Nginx Logs in Private Cloud?

1. Edit your router.properties, create it if it does not exist, here:

/opt/apigee/customer/application/router.properties 

2. Add the following two lines inside the router.properties:
conf_load_balancing_load.balancing.driver.nginx.global.http.parameters.template.extra=log_format le_json '{ "time": "$time_iso8601", '\\\
\n\\n '"remote_addr": "$remote_addr", '\\\
\n\\n '"remote_user": "$remote_user", '\\\
\n\\n '"body_bytes_sent": "$body_bytes_sent", '\\\
\n\\n '"request_time": "$request_time", '\\\
\n\\n '"status": "$status", '\\\
\n\\n '"request": "$request", '\\\
\n\\n '"request_method": "$request_method", '\\\
\n\\n '"http_referrer": "$http_referer", '\\\
\n\\n '"http_user_agent": "$http_user_agent", '\\\
\n\\n '"x-forwarded-for": "$http_x_forwarded_for", '\\\
\n\\n '"x_apigee_fault_flag": "$upstream_http_x_apigee_fault_flag", '\\\
\n\\n '"x_apigee_fault_source": "$upstream_http_x_apigee_fault_source", '\\\
\n\\n '"x_apigee_fault_code": "$upstream_http_x_apigee_fault_code", '\\\
\n\\n '"x_apigee_fault_policy": "$upstream_http_x_apigee_fault_policy", '\\\
\n\\n '"x_apigee_fault_flow": "$upstream_http_x_apigee_fault_flow", '\\\
\n\\n '"x_apigee_fault_revision": "$upstream_http_x_apigee_fault_revision", '\\\
\n\\n '"x_apigee_target_latency": "$upstream_http_x_apigee_target_latency" }';\\\
\n\\n
conf_load_balancing_load.balancing.driver.nginx.access.log=${conf_load_balancing_load.balancing.driver.nginx.log.dir}/${org}~${env}.${port}_access_log le_json


3. Restart the router:

apigee-service edge-router restart 

4. repeat on all routers

Router logs are located in the following directory:

/opt/apigee/var/log/edge-router/nginx

Logs are named in the format of org~env.port_access_log.

Sample log entry:

{ "time": "2017-08-04T23:22:41+00:00", "remote_addr": "127.0.0.1", "remote_user": "-", "body_bytes_sent": "0", "request_time": "0.001", "status": "200", "request": "GET /no-target HTTP/1.1", "request_method": "GET", "http_referrer": "-", "http_user_agent": "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2", "x-forwarded-for": "-", "x_apigee_fault_flag": "-", "x_apigee_fault_source": "-", "x_apigee_fault_code": "-", "x_apigee_fault_policy": "-", "x_apigee_fault_flow": "-", "x_apigee_fault_revision": "-", "x_apigee_target_latency": "-" }
Comments
Not applicable

I came across this and it is very useful. However I see that the x-forwarded-for has a "-" instead of the actual original IP. why is that?

"x-forwarded-for":"-",
frankliu1
Staff

Instead of

'"x-forwarded-for": "$http_x_forwarded_for", '

Please try

'"x-forwarded-for": "$my_nginx_var_xff", '
Version history
Last update:
‎08-04-2017 04:51 PM
Updated by: