Change the default port number for Sitecore 10 in Container

You may saw the following error if you try to change the default port number from 443:

Invalid URI: The hostname could not be parsed.

Sitecore 10 just released a few days ago. With Sitecore 10, it's much easier to try Sitecore in the container.

Following the tutorial to setup my first Sitecore instance, everything is works smoothly except i have to stop my other sites first. Because of the port conflict. Sitecore container use the following ports by default: 443, 8079, 8081, 8984, and 14330. Most of them are Okay, except 443. The default SSL port number, which has been used by IIS for other Sitecore sites.

Can we change 443 to a different port? like 8443?

1. Change the entrypoints for traefik service.

2. Create a processor to update the X-Forwarded-Host header to remove the port number from the header. If not, you will get an exception like below:

This is because of the X-Forwared-Host header include the port number in the host name.

Maybe we can remove the header or update the header value by update the traefik setting or we remove the port number in the code:

 public override void Process(PreprocessRequestArgs args)
{
var context = HttpContext.Current;
string str = context?.Request?.Headers?[Settings.LoadBalancingHost];
if (!string.IsNullOrEmpty(str) && str.Contains(":"))
{
str = str.Substring(0, str.IndexOf(":"));
context.Request.Headers[Settings.LoadBalancingHost] = str;
}
}

3. Update the Sitecore Identity server configuration to use new port number