Howdy Steve,
> I have a requirement from a customer that the terminal slash be
> rewritten when accessing the homepage - eg example.com/ is a 301 to
> example.com
> I've tried a simple rewrite of ^/$ but that just loops.
In the given example request "example.com", the path is going to be the same for both when the trailing slash is present and when it is not. The request being sent to nginx from the client is identical in both situations, both will result in "GET / HTTP/1.1".
If you want to confirm the behavior yourself, you can tcpdump the requests and observe for yourself that there are no differences. Nginx can't distinguish between example.com and example.com/.
I hope this helps to clarify things!
Kevyn