Since its 2013 version, Canonical Tags in SharePoint are supported by default if you enable the Publishing Feature. You can also use Managed Navigation to have Friendly URLs and make your canonical tags look awesome!

These Canonical URLs are important to help Search Engines on their task for categorization, simplifying tracking metrics and consolidating links and references that may have different URL formats, but point to the same page. You can find more info in this post.

The ports displayed in the Canonical Tags

It’s important to say that it may add ports to the Canonical tag and it’s by design, you can’t remove it unless you comment some code in Feature XMLs. But be warned that if you upgrade your environment and install new SharePoint updates, you may lose what you did.

<link rel="canonical" href="https://sharepointurl:443/" />
<!-- or -->
<link rel="canonical" href="http://sharepointurl:80/" />

No, seriously.. there’s no way to remove the port without that customization. It happens because in the SeoCanonicalLink control, SharePoint will always encode the URL using a UriBuilder object that inserts the port.

Seo Canonical Link control trying to encode your loved URL
Here the Uri Builder will create the URL with the Port

The Internet Zone and Canonical Tags

SharePoint will use the URL to render the canonical tag will be a combination of what you informed in the Internet Zone inside the Alternate Access Mappings. If nothing is informed, then it will use the Default zone to render the canonical tags in SharePoint.

Image result for Alternate Mapping Access
All possible options of Public URLs for AAM

Getting the Canonical Tags from SharePoint via C#

If you want to find out through C# what is the Canonical URL for the current page, you can get and update it accessing the HTTP Context items like below. you can also update it, setting a new string URL but SharePoint will try to update and format it in its own control:

string canonicalUrl = HttpContext.Current.Items["CanonicalURLWithParameters"];
HttpContext.Current.Items["CanonicalURLWithParameters"] = "https://newUrl";

Consolidating canonical URLs

Finally, you can specify some URL parameters that will be considered as different from others, even if it’s the same page. Take as an example a Product List page that can be filtered or sorted. If you define some parameters, separated by semicolons, you are helping SharePoint on differentiating the results and increasing the radius and crawl depth.

Also if you want to learn how to update the SEO properties in a easy way, please check my post on how to update your SharePoint SEO Properties programmatically.

Furthermore, you can check this book that may help you on learning all the best practices in 2019 for Search Engine Optimization:

References:
Social Technet – SharePoint 2013 canonical links adding port numbers;
Alternate Access Mapping overview;
What are canonical Tags;