Fediverse account on user@example.com instead of user@cloud.example.com

My nextcloud instance is running on cloud.example.com.
How can I set the fediverse hostname to example.com
I have tried to put a rewrite in the nginx config for example.com

rewrite ^/.well-known/webfinger https://cloud.example.com/public.php?service=webfinger;

This does not seem to work.

Any suggestions?

It seems to be working by adding following to the example.com config:

   location  ~ /\.well-known/webfinger {
        allow all;
        proxy_set_header Host "cloud.example.com";
        proxy_pass https://127.0.0.1$request_uri;
    }
    location  ~ /apps/social/ {
        allow all;
        proxy_set_header Host "cloud.example.com";
        proxy_pass https://127.0.0.1$request_uri;
    }

I still have issues federating with some instances, but this can be due to other bugsā€¦
If someone has a better config for nginx, please reply, as i donā€™t know if this will be leaking info anywhere.