Nextcloud uses IP instead of Domain and therefore SSL is not working

Hi,

my Nextcloud instance is hosted on a virtual server on a remote host. I used the Debian Stretch image of NextcloudPi and installed it via
curl -sSL https://raw.githubusercontent.com/nextcloud/nextcloudpi/master/install.sh | bash.

I setup an A record so that my subdomain is pointing to the remote host of the vm. Everything works fine and I can access the Nextcloud instance by typing in the subdomain and / or the ip adress. After setting up Let’s encrypt by using the integrated tool from npc-config I noticed that the login page is shown correctly with my subdomain and SSL works, but as soon as I login a new tab is opened which shows the warning that SSL isn’t correctly configured. The adress bar in the new tab is showing the IP adress instead of the domain so the warning makes sense, of course Let’s encrypt is only configured for the domain name.

The Let’s encrypt tool added a virtual host in my nextcloud.conf and the server name is set to my subdomain. In config.php I checked that the first entry of my trusted domains is my subdomain, which it is, and also the line ‘overwrite.cli.url’ is set to my subdomain.

I found this post (Show domain instead of IP address) describing how I could tell Nextcloud to use my subdomain, but unfortunately it didn’t work.
Of course I restarted apache2 and after that even the whole vm, but still it redirects to the IP adress after I login.

Anything I’m missing here?