Http logo urls after enabling LetsEncrypt

I tried a a fresh install on a new vps, but it broke again after importing data. After lots of googling and going through source code, I found out my Discourse.BaseUrl had port 80 forced into it. I tracked it down to these lines in discourse.rb:

 default_port = SiteSetting.force_https? ? 443 : 80
 url = +"#{base_protocol}://#{current_hostname}"
 url << ":#{SiteSetting.port}" if SiteSetting.port.to_i > 0 && SiteSetting.port.to_i != default_port

As a temporary fix, I commented out the last line, rebaked all the posts and that fixed everything for me.

Then I looked at my sql dump from the previous site export, and found out that port was set to 80 in site_settings (as I’ve mentioned, the original install didn’t have SSL). It didn’t match the port 443 which is expected from a site with force_ssl, and 80 was inserted into BaseUrl. So, I guess the proper fix is to change SiteSetting.port to 443 and then rebake.