For reasons related to CPU performance, RAM, software availability (PHP, MariaDB, various file-preview tools), ZFS, and security, NextCloud runs in a FreeBSD jail on either an APU3C4 or an ODROID H2. It is behind a reverse proxy on a restricted subnet as well (outside world --> firewall --> router --> reverse proxy --> NextCloud). Your favorite regularly updated, Linux-based server/desktop distro would be a good choice as well (Debian, for example). I wouldn't run either directly on the router itself.
DDNS if your assigned IP changes quickly, with Let's Encrypt certificates.
Nextcloud is quite resource heavy software so I'll recommend using a powerful board like PC Engines APU2 series as a foundation of your server. Since you haven't specified your budget and storage needs I've got no idea if you'd like better a nice internal SSD (nowadays you can get 480GB mSATA for around 50 EUR) or a big external HDD connected via USB 3.0.
If you're not sure what operating system to use I would strongly recommend Devuan GNU/Linux distribution (it's basically fork of Debian but without systemd malware), modern web server like nginx or lighttpd and MariaDB SQL database engine (it's 100% compatible with Oracle's MySQL - just better). If you need it you can of course deploy Jabber/XMPP server on the same machine - use Prosody software (rock solid, very lightweight).