Changing discourse from domain to subdomain?

Technically, sub.example.com is different than example.com despite being part of same domain. You can safely follow those instructions replacing example.com with discourse.example.com and it will migrate your forum to the subdomain.

Apart from rebuild the remap command should be:

discourse remap example.com discourse.example.com