You need to change the before your rebuild. And if you’re going to change the host name it’s easier to backup and restore. Else you need to follow Change the domain name or rename my Discourse?.
You can move the backup with scp and restore from the command line.