If your site is accessible at http(s)://mydomain/nextcloud, you must add :
rewrite ^/.well-known/host-meta /nextcloud/public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /nextcloud/public.php?service=host-meta-json last;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
}
But, if your URL is http(s)://mydomain : you must add :
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
All in the documentation :
https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
EDIT : The configuration is updated for each new version of NC, so its better to check the doc ( the configuration above works for NC18 but not for NC19 and higher). The link is by default the latest configuration available.
Good luck