Use same domain, but differ with port

Can you re-phrase your question?

A port is used by an entrypoint. A router can be assigned to one or more entrypoints. A service can be assigned to one or more routers.

Maybe have a look at this post.

If you use different ports and entrypoints with the same router and same service:

https://sub.example.com/
https://sub.example.com:8443/

then the target service can only figure out by request header which one was used.

Of course you can setup different routers, middlewares and services for each port/entrypoint.