Discourse rebuild fails with port 443 in use

sudo apt remove nginx

Why did you install nginx on the host? If you installed it by accident it may be safe to remove.