Site icon Hip-Hop Website Design and Development

How to access wordpress from domainB which is installed at domainA

Use Case:

I am setting up wordpress for one of my clients. The wordpress is setup at a domain like http://cms.domainA.com. This domain is on VPN which can only be accessed by using VPN and few additional software. To make the wordpress accessible from the main website there are proxies are created such that https://cms.domainB.com pointing to http://cms.domainA.com.
https://cms.domainB.com is publicily accessible.

What I want here is wordpress to load normally with all wp-admin, login functionality, post creation etc working from https://cms.domainB.com also.

Here is the nginx configuration:

server_name  cms.domainB.com;

        location / {
                 proxy_pass http://stg-traefik;
                 proxy_set_header Host "cms.domainA.com";
                 proxy_http_version 1.1;
                 proxy_set_header Connection "";
                 proxy_set_header X-Forwarded-Proto $scheme;
                 add_header X-Frame-Options "DENY" always;
                 add_header X-Content-Type-Options "nosniff" always;
                 add_header X-XSS-Protection "1; mode=block" always;
                 add_header strict-transport-security "max-age=31536000; includeSubDomains; preload" always;
        }
}

This nginx is verified and works well for other node and react projects needing similar approach.

W.r.t wordpress, all the script, css urls in the page are absolute urls due to which it tries to access resource from http://cms.domainA.com when opening https://cms.domainB.com and fails.
I have tried other approaches also to update wordpress address url and site address url from wordpress page, wp config etc but they are not of any help.

The only solution which seems to be partially working is modify esc_url function in wp-includes/formatting.php to return relative url but for that, I would have to manually modify the functionality in the wordpress core which I don’t want to do. All the urls accessible from cms.domainA.com are also opening from cms.domainB.com if I copy paste them in new tab. The issue is that wordpress while generating html; makes all urls absolute.

Current HTML structure (when loading https://cms.domainB.com)

Observe here, all urls are absolute so even though proxies are correct -> as cms.domainA.com is behind VPN, it doesn’t work properly.

Partial Possible working solution (when loading https://cms.domainB.com)

Observer here, most urls are relative so they load well with a lot of functionality working well

Is there a way to make all urls relative to install location or Is there a way to update absolute urls based on from where request is coming or Is there a third better way that can be used here?

Any help will be highly appreciated. Let me know if there are any further clarifications needed.