Gostaria de sugerir esta abordagem:
# remove multiple sequences of forward slashes
# rewrite URI has duplicate slashes already removed by Nginx (merge_slashes on), just need to rewrite back to current location
# note: the use of "^[^?]*?" avoids matches in querystring portion which would cause an infinite redirect loop
if ($request_uri ~ "^[^?]*?//") {
rewrite "^" $scheme://$host$uri permanent;
}
Ele usa o comportamento padrão de nginx - mesclar barras, então não precisamos substituir barras, simplesmente redirecionando