Created
March 21, 2019 20:30
-
-
Save codeasashu/415081525e201b55a3bd33844c046d9e to your computer and use it in GitHub Desktop.
nginx json logging
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
#log_format custom '$request_body'; | |
log_format custom '$remote_addr - $remote_user [$time_local] ' | |
'"$request" $status $bytes_sent ' | |
'"$http_referer" "$http_user_agent" "$request_body"'; | |
log_format json_combined escape=json | |
'{' | |
'"time_local":"$time_local",' | |
'"remote_addr":"$remote_addr",' | |
'"remote_user":"$remote_user",' | |
'"request":"$request",' | |
'"status": "$status",' | |
'"body_bytes_sent":"$body_bytes_sent",' | |
'"request_time":"$request_time",' | |
'"request_body":"$request_body",' | |
'"http_referrer":"$http_referer",' | |
'"http_user_agent":"$http_user_agent"' | |
'}'; | |
upstream remotees { | |
#server http://elastic.service.consul:9200; | |
server 13.233.249.192:9200; | |
} | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
server_name localhost; | |
location /insert { | |
access_log /var/log/nginx/post.log json_combined; | |
proxy_pass http://127.0.0.1/post_gif; | |
} | |
location / { | |
if ($request_method = GET) { | |
proxy_pass http://remotees; | |
access_log /var/log/nginx/get.log custom; | |
} | |
} | |
location = /post_gif { | |
# turn off logging here to avoid double logging | |
access_log off; | |
return 200 'OK'; | |
} | |
access_log /var/log/nginx/access.log; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment