WordPress installed on a virtual machine and behind a reverse proxy is redirecting to the VM’s IP address

I found the solution to this. Apparently going to wp-includes/canonical.php and changing the line $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); to $redirect_url = null; fixes this behavior, though it’s a unstable fix since it’ll be overwritten by updates.

Why is this so hard to get working? Every other webserver software I’ve used has not had a problem with virtual machines behind reverse proxies.