Installing OnlyOffice Document Server on the same Machine as NextCloud is Installed
ONLYOFFICE Document Server can be installed on the same Ubuntu O/S machine as your Nextcloud instance or on a different one. In case you select the first variant, you will need to set up a custom port for Document Server as by default port for both ONLYOFFICE Document Server and Nextcloud is TCP port 80.
The next issue may be providing separate SSL certificates for the NextCloud instance on port 443, and using no SSL or a separate SSL certificate for Document Server. Each may be operating on separate fully qualified secondary domain names. Or maybe they need to be setup on the same qualified domain but using different host headers and install an SSL certificate that contains and supports the SSL encryption/decryption for each of the configured host headers.