Exclude multiple query parameters from being logged in Nginx?

Solution 1:

You can cascade map statements. It may not be very efficient, but it is easily extended. Also, you will need to use named captures, as the numeric captures will be overwritten.

For example:

map $request $custom1 {
    ~^(?<prefix1>.*[\?&]latitude=)([^&]*)(?<suffix1>.*)$  "${prefix1}***$suffix1";
    default                                               $request;
}
map $custom1 $customrequest {
    ~^(?<prefix2>.*[\?&]longitude=)([^&]*)(?<suffix2>.*)$ "${prefix2}***$suffix2";
    default                                               $custom1;
}