How to set up /etc/hosts for nextcloud-snap and dynamic DNS with reverse proxy

I have a server in my home network running Nextcloud 27 snap.
I have a dynamic DNS pointing to my network, therefore I use Nginx proxy manager to manage a couple of domains. Nginx proxy manager handles SSL.

I set up everything as indicated in https://github.com/nextcloud-snap/nextcloud-snap/wiki/Putting-the-snap-behind-a-reverse-proxy and then as in Hosts and FQDN for Nextcloud snap 路 nextcloud-snap/nextcloud-snap Wiki 路 GitHub which means I disabled https in nextcloud, I set overwriteprotocol, overwritehost and overwrite.cli.url properly, and I edited to my /etc/hosts file:

127.0.0.1 localhost
127.0.1.1 home_server
172.18.0.2  nextcloud.mydomain.tld

I replaced mydomain.tld with my actual domain, obviously. 172.x.x.x is the IP of the Nginx proxy container, since the guide stated:

your.reverse.proxy.ip       your.domain.xyz hostname

Well, accessing Nextcloud via the URL from outside the network works, tested via Android, but it doesn鈥檛 from local network. Accessing via local network IP works.

I can see in Adguard Home that Adguard rewrites the DNS request 鈥渘extcloud.mydomain.tld鈥 to 鈥172.18.0.2鈥, reason 鈥渓ocal hosts file鈥.

Well, that third line in /etc/hosts has to be deleted to make it work. Let the router do its job of NAT loopback (I think it鈥檚 called that way) so that when it detects from inside the network a (let鈥檚 use inappropriate but understandable wording) call (request for a URL) coming from inside the network, which turn out it鈥檚 actually for for itself (the IP address is the public one the router has on its outside), it will redirect the traffic to the internal IP which would be 鈥渃onnected鈥 is someone from outside were to connect to the router.

Whether it would work by adding my domain to either 127.0.0.1, or by a new line with the internal IP of the server, I don鈥檛 know. People with more skills and time can provide tips and explanations.