Non-www to www redirect using Nginx

I’ve been trying to figure out how to setup a non-www to www domain redirect on a virtual host within Virtualmin with no luck.

The only way I’ve been able to get this to work is by manually editing the nginx config for the virtual host and using the following:

if ($host = '') { rewrite ^/(.*)$$1 permanent; }

Does anyone know how this can be achieved within Virtualmin or if there is a better way of doing this?

Many thanks.