OK, installed a fresh WordPress instance. Same results. Just to confirm, you're testing the, ensuring that you are NOT adding the trailing slash to https://local-dev-site.mydomain.com/wp-admin (<-- NO TRAILING SLASH)?
If I add the trailing slash everything is fine. If I just go to https://local-dev-site.mydomain.com/wp-admin (<-- NO TRAILING SLASH), that's when I get the port number in the URL. I've added that code you requested for further debugging. I added it to debug-headers.php and these are the results:
Cookie: wordpress_test_cookie=WP%20Cookie%20check; MicrosoftApplicationsTelemetryDeviceId=5859edc0-425d-4063-94b8-6bf065a6d23f; MicrosoftApplicationsTelemetryFirstLaunchTime=2025-12-17T14:13:05.938Z; wp_lang=en_US
Accept-Language: en-CA,en;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Sec-Fetch-Dest: document
Sec-Fetch-User: ?1
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Upgrade-Insecure-Requests: 1
Cache-Control: no-cache
Pragma: no-cache
Connection: close
X-Forwarded-Host: local-dev-site.mydomain.com
X-Forwarded-For: ::1
X-Real-Ip: ::1
Host: local-dev-site.mydomain.com
Content-Length:
Content-Type:
SERVER_PORT: 50015
This all looks normal. And based on my original troubleshooting, I wouldn't expect the port to be involved here. The ONLY time I end up with the port in the URL is when I go to https://local-dev-site.mydomain.com/wp-admin (<-- NO TRAILING SLASH). To get some additional debug info for you, I've added a modified version of thaat code to my functions.php and am outputting the results to console (so you can see the same information as I progress through the steps to eventually end up with the port in the URL. So, here are those results:
URL: https://local-dev-site.mydomain.com/
RESULTS:
Cookie: wordpress_test_cookie=WP%20Cookie%20check; MicrosoftApplicationsTelemetryDeviceId=5859edc0-425d-4063-94b8-6bf065a6d23f; MicrosoftApplicationsTelemetryFirstLaunchTime=2025-12-17T14:13:05.938Z; wp_lang=en_US
Accept-Language: en-CA,en;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Sec-Fetch-Dest: document
Sec-Fetch-User: ?1
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Upgrade-Insecure-Requests: 1
Cache-Control: no-cache
Pragma: no-cache
Connection: close
X-Forwarded-Host: local-dev-site.mydomain.com
X-Forwarded-For: ::1
X-Real-Ip: ::1
Host: local-dev-site.mydomain.com
Content-Length:
Content-Type:
SERVER_PORT: 50015
Next, I go to...
https://local-dev-site.mydomain.com/wp-admin (<-- NO TRAILING SLASH)
...which immediately redirects to...
https://local-dev-site.mydomain.com/wp-login.php?redirect_to=https%3A%2F%2Flocal-dev-site.mydomain.com%3A50015%2Fwp-admin%2F&reauth=1
It's this redirect—from wp-admin (<-- NO TRAILING SLASH) to wp-login.php where the port (50015) is first introduced. You can see it in the redirect parameter; it's not yet in the main URL, just the redirect parameter. And these are the resuts after that redirect:
Cookie: wordpress_test_cookie=WP%20Cookie%20check; MicrosoftApplicationsTelemetryDeviceId=5859edc0-425d-4063-94b8-6bf065a6d23f; MicrosoftApplicationsTelemetryFirstLaunchTime=2025-12-17T14:13:05.938Z; wp_lang=en_US
Accept-Language: en-CA,en;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Sec-Ch-Ua-Platform: "macOS"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"
Sec-Fetch-Dest: document
Sec-Fetch-User: ?1
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Upgrade-Insecure-Requests: 1
Cache-Control: no-cache
Pragma: no-cache
Connection: close
X-Forwarded-Host: local-dev-site.mydomain.com
X-Forwarded-For: ::1
X-Real-Ip: ::1
Host: local-dev-site.mydomain.com
Content-Length:
Content-Type:
SERVER_PORT: 50015
Again, this is normal. No port in the actual URL yet. But it is in the redirect parameter from where these results were captured.
Finally, as I'm now on the login screen, when I log in, I end up on this URL:
https://local-dev-site.mydomain.com:50015/wp-admin/
The port number is now in the URL. And these are the results:
Cookie: MicrosoftApplicationsTelemetryDeviceId=98ee73f9-ce34-49b7-af98-af1b18271dfc; MicrosoftApplicationsTelemetryFirstLaunchTime=2025-12-17T14:08:54.170Z; wordpress_sec_3d96e7a4a99c84acef7d9913bd44b58c=kmaling%7C1766154541%7C7GVRUQmbWfz4Tv4epjEUGIDT5Dcg1k0yXuQcQEHRTMV%7Cfa3adede33566181cd0f20b347c9256e4c778f04c6e808eb5d7fdfa3f25933c3; wordpress_test_cookie=WP%20Cookie%20check; MicrosoftApplicationsTelemetryDeviceId=5859edc0-425d-4063-94b8-6bf065a6d23f; MicrosoftApplicationsTelemetryFirstLaunchTime=2025-12-17T14:13:05.938Z; wp_lang=en_US; wordpress_logged_in_3d96e7a4a99c84acef7d9913bd44b58c=kmaling%7C1766154541%7C7GVRUQmbWfz4Tv4epjEUGIDT5Dcg1k0yXuQcQEHRTMV%7C2f6fa1abc5dbd7c5d549c72beb67f3a30cf701089cef662c11fa231a26833c4f
Accept-Language: en-CA,en;q=0.9
Accept-Encoding: gzip, deflate, br, zstd
Referer: https://local-dev-site.mydomain.com/
Sec-Ch-Ua-Platform: "macOS"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"
Sec-Fetch-Dest: document
Sec-Fetch-User: ?1
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-site
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Upgrade-Insecure-Requests: 1
Cache-Control: no-cache
Pragma: no-cache
Connection: keep-alive
Host: local-dev-site.mydomain.com:50015
Content-Length:
Content-Type:
SERVER_PORT: 50015
The port nuber is now appearing in the results (host).
Finally, if I start over (log out, new window, etc.), and go here, manually adding the trailing slash this time...
https://local-dev-site.mydomain.com/wp-admin/ (<-- TRAILING SLASH MANUALLY ADDED)
...it immediately redirects to...
https://local-dev-site.mydomain.com/wp-login.php?redirect_to=https%3A%2F%2Flocal-dev-site.mydomain.com%2Fwp-admin%2F&reauth=1
And, unlike the previous attemp, when there is NO trailing slash, this time, because the trailing slash WAS added, the port doesn't end up in the redirect parameter.
So, this looks like there's something going on with the redirect of wp-admin specificialy, and only when there is no trailing slash included. This does not happen when trailing slashes are omited on other paths, like...
https://local-dev-site.mydomain.com/wp-login
That redirects properly to...
https://local-dev-site.mydomain.com/wp-login/
This only happens on https://local-dev-site.mydomain.com/wp-admin (<-- NO TRAILING SLASH)
Hoping this might narrow things down a little?