Nginx で trailing slash 付きの URL にリダイレクトしたいとき

Nginx で trailing slash (URL 末尾の /) 付きの URL にリダイレクトしたいとき、 nginx trailing slash みたいな感じでググるrewrite とかを使った例がたくさん見つかる。しかし、これより先に知っておきたい挙動として、特定条件下で location の設定の設定によってリダイレクトが起こることがあり、ドキュメントにも記載されている。

If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, or memcached_pass, then the special processing is performed. In response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended.

http://nginx.org/en/docs/http/ngx_http_core_module.html#location

だいたいの場合はこの location の挙動だけで困らないんだろうけど、どうしても自分で rewrite でリダイレクトを設定したい場合にこちらの存在も意識しておかないと混乱する(混乱した)。