It’s hard to say from what you shared. Please review your browser console/dev tools and check if there is a redirect to localhost. Nextcloud must be aware of the (public) URL where the user can access the system. This could be lost behind reverse proxy and you might need to setup overwritehost and oder reverse proxy headers to configure right redirect - see 101: reverse proxy for details