Reputation: 1205
I want to log POST data in NGINX and am using $request_body to do the same.
But there are POST fields that I don't want to log (like password, email etc). Is it possible to parse the post data OR asynchronously send data to a PHP/RUBY or any other script so that i can parse the POST data there ?
Upvotes: 1
Views: 2029
Reputation: 1205
I achieved this by using Nginx LUA module. and then by calling ngx.req.get_post_args()
in the lua script, i was able to get the post content in the form of a table (LUA's arrays). Hence parsing this in lua itself removing unnecessary parameters and logging it solved this issue.
Upvotes: 1
Reputation: 2061
It's not possible to access post parameters directly with default modules, but you could try to make little hack , to achieve this. This is the example:
location /forPost {
try_files /logger.php $uri;
}
The script should always return 404 status, this is exampe:
<?php
if (isset($_POST['data']) ) {
logger($_POST['data']);
}
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
header("Status: 404 Not Found")
die();
?>
Upvotes: 1