Logging POST data from $request_body

前端 未结 7 1537
日久生厌
日久生厌 2020-11-27 10:52

I have my config setup to handle a bunch of GET requests which render pixels that work fine to handle analytics and parse query strings for logging. With an additional third

7条回答
  •  离开以前
    2020-11-27 11:46

    The solution below was the best format I found.

    log_format postdata escape=json '$remote_addr - $remote_user [$time_local] '
                           '"$request" $status $bytes_sent '
                           '"$http_referer" "$http_user_agent" "$request_body"';
    server {
            listen 80;
    
            server_name api.some.com;
    
            location / {
             access_log  /var/log/nginx/postdata.log  postdata;
             proxy_pass      http://127.0.0.1:8080;
            }
    
    }
    

    For this input

    curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://api.deprod.com/postEndpoint
    

    Generate that great result

    201.23.89.149 -  [22/Aug/2019:15:58:40 +0000] "POST /postEndpoint HTTP/1.1" 200 265 "" "curl/7.64.0" "{\"key1\":\"value1\", \"key2\":\"value2\"}"
    

提交回复
热议问题