Created
October 30, 2015 03:53
-
-
Save joshuar/38a0196d29a9bc7bd971 to your computer and use it in GitHub Desktop.
Logging Elasticsearch HTTP API Requests with Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
error_log /var/log/nginx/error.log; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
log_format es '$remote_addr - $remote_user [$time_local] ' | |
'"$request" $status $body_bytes_sent' | |
'"$http_referer" "$http_user_agent" {$request_body}'; | |
access_log /var/log/nginx/access.log es; | |
upstream elasticsearch { | |
server 10.250.250.1:9200; | |
} | |
server { | |
listen 8080; | |
location / { | |
proxy_http_version 1.1; | |
proxy_set_header Connection ""; | |
proxy_connect_timeout 5s; | |
proxy_read_timeout 10s; | |
proxy_pass http://elasticsearch; | |
} | |
} | |
} |
like this:
log_format log_json escape=json '{"timestamp": "$time_local",'
'"remote_addr": "$remote_addr",'
'"referer": "$http_referer",'
'"request": "$request",'
'"status": "$status",'
'"byte": "$body_bytes_sent",'
'"agent": "$http_user_agent",'
'"x_forwarded_for": "$http_x_forwarded_for",'
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"up_resp_time": "$upstream_response_time",'
'"request_body": "$request_body",'
'"request_time": "$request_time"}';
make sure your nginx version >= 1.11.8
ref: http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, How to print "\x0A" directly, do not line feed?