## Simple logging Api in nginx A HTTP POST API `/log` for hobby apps. 1. log rotate by `/etc/logrotate.d/nginx` without extra configuring 2. api limit by `limit_req_zone` 3. app client might add a sample rate to prevent abuse requests such as sentry javascript sdk [sample rate 0 to 1](https://github.com/getsentry/sentry-javascript/blob/master/packages/core/src/baseclient.ts#L550) `/etc/nginx/sites-enable/default.conf` ``` ..... limit_req_zone $binary_remote_addr zone=mytracking:10m rate=10r/s; log_format my-tracking-format escape=json '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" "$request_body"'; server { listen 80 default_server; ..... location = /log { limit_req zone=mytracking burst=20 nodelay; access_log /mnt/logs/nginx/my-tracking.access.log my-tracking-format; proxy_pass http://localhost:80/empty; } location = /empty { access_log off; return 200 'logged'; } ..... } server { listen 443 ssl; ..... location = /log { limit_req zone=mytracking burst=20 nodelay; access_log /mnt/logs/nginx/my-tracking.access.log my-tracking-format; proxy_pass http://localhost:80/empty; } ..... } ``` version: `nginx version: nginx/1.14.0 (Ubuntu)` ### Test request `curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST https://yourserver.com/log` checking log `tail -f /var/log/nginx/my-tracking.access.log` references: https://stackoverflow.com/questions/17609472/really-logging-the-post-request-body-instead-of-with-nginx https://stackoverflow.com/a/14034744/6414615