Thanks a lot for your attention and kindness in replying.
I think I had used the official doc you commented to setup my instance. As far as I can tell, everything was supposed to be working. Even logging in through moodle's android app works.
But maybe there is something that changed or has been added on the docs. I will check again and report back.
The certificate I'm using is not self-signed, it's a Let's Encrypt one. Just double checked and the current one is valid until April.
Both Moodle and Nextcloud are on the same instance, could that interfere in any sense?
Let's Encrypt should be fine. The fact that Moodle and Nextcloud are on the same server should not be an issue either. Unless, maybe, this results in different hostnames (for example, maybe the public hostname of your server cannot be resolved locally - that would be an issue, because after authorisation Moodle talks to Nextcloud directly using that hostname).
in my experience, the issues with misconfigured WebDAV + headers are hard to notice, i.e. everything appears totally fine except for a few very special requests that fail without a helpful error message. For example, I have no idea whether the rather special combination of Nextcloud's OAuth + WebDAV + nginx works, and whether those behind that documentation have even tried it. (For example, on misconfigured Apaches, the OAuth authentication header is just dropped without notice - but everything else is fine.)
If you double-checked the configuration and it doesn't work yet, you could try two things. You could ask the Nextcloud community for help on their forums. Maybe they have experience with nginx + OAuth that they are willing to share. Alternatively, try setting up your Nextcloud on an Apache following the official documentation; then try connecting to that.
Good luck, hope this helps!
I've double-checked the nginx configuration, did some minor tweaks, but it still does not work.
I'll try to reach the nextcloud forum, then.