Azure / wordpress-linux-appservice

MIT License
105 stars 70 forks source link

MultiSite FrontDoor configuration with custom domains #92

Closed karpikpl closed 1 year ago

karpikpl commented 1 year ago

Hi, I've configured a multi-site wordpress instance with Front Door.

Front Door has 3 routes that proxy traffic to the app service:

My network admin -> sites configuration looks like this:

The sites look OK when initially opened. The custom domain is used and site1 path is correctly added by FrontDoor. The problem is that all the links are absolute and use wordpressp-xxx.azurefd.net instead of custom domain.

I tried changing site configuration:

What's the correct setup for this custom domain -> multi-site deployment?

rabollin commented 1 year ago

@ZubaeyrMSFT - seems to be some URL redirection configuration setup, look into this issue on priority.

ZubaeyrMSFT commented 1 year ago

@karpikpl

Please note that a Multisite WordPress can be associated and accessed with only one domain. You have used an AFD endpoint for installing the multisite (wordpressp-xxx.azurefd.net). And therefore, the WP is configured with it, and all the embedded links would point to it.

Few questions I wanted to understand. Are you looking for a subdomain-based multisite or subdirectory-based multisite? I see that you have installed subdirectory multisite and trying to access it like a subdomain one?

Please follow the instructions here: How to enable multisite WordPress on App Service and also refer to the Important Notes section in there.

These are the steps for converting a new single site to multisite (assuming AFD is already integrated with App Service and necessary app settings are added as mentioned here)

  1. Map all the required custom domains to the AFD endpoint. customdomain.org, site1.customdomain.org, site2.customdomain.org etc.,

  2. Add the following App Settings to install subdomain based multisite. This will only work if multisite isn't installed already. CUSTOM_DOMAIN - customdomain.org WORDPRESS_MULTISITE_TYPE - subdomain WORDPRESS_MULTISITE_CONVERT - true

  3. Add the following App Setting to install subdirectory based multisite. This will only work if multisite isn't installed already. CUSTOM_DOMAIN - customdomain.org WORDPRESS_MULTISITE_TYPE - subdirectory WORDPRESS_MULTISITE_CONVERT - true

ZubaeyrMSFT commented 1 year ago

If you want to update your current multisite to point to custom domain. You can try manual steps mentioned below.

  1. Map all the required custom domains to the AFD endpoint.
  2. Add CUSTOM_DOMAIN app setting to your App Service. (ex: customdomain.org)
  3. In order to change the domain associated with the multi-site post installation, you might have to manually update the occurrence of the old domain name in the MySQL database tables (i.e., replace occurrence of AFD endpoint with custom domain). Some common tables to look for are wp_options, wp_site, wp-blog, wp_users, wp_usermeta, wp_sitemeta and so on. Moreover, there can be specific sub-site tables (wp_2_site, wp_2_options etc.,). You can use /phpmyadmin to access your database.
karpikpl commented 1 year ago

I was trying to have a mix of multi-site and multi-domain.

I think that's what author of #84 did. Having wordpress configured with multi-site directory but AFD configured with multiple domains, e.g:

myfirstdomain.com -> wordpressp-xxx.azurefd.net/site1 myseconddomain.com -> wordpressp-xxx.azurefd.net/site2

but from what you're saying that's not possible - one wordpress instance == one domain? Only sub-domains can be used?

ZubaeyrMSFT commented 1 year ago

Yes, you are right. Multisite supports only one main domain at a time. May I know if there are any reasons for using the mixed approach? And why not just use subdomain based multisite? It's better go with purely subdomain-based multisite in this case.

karpikpl commented 1 year ago

Thanks for all the answers and support! I was trying to follow this - https://www.wpbeginner.com/wp-tutorials/how-to-create-a-wordpress-multisite-with-different-domains/ where different domains were possible.

I thought with AFD I can hide paths or set headers to make it work...

karpikpl commented 1 year ago

I went with subdomain route. I verified with /phpmyadmin that all values are correct. I checked that FD is setting custom host header on the route -> the subdomain one site3.wp.xxx.org. It was also added to app service as custom domain.

It doesn't work for me though - I cannot view the site (it shows the main one on wp.xxx.org) and I was getting CORS errors, so I've added subdomains to my App Service settings.

Still getting errors though:

Uncaught DOMException: Failed to execute 'replaceState' on 'History': A history state object with URL 'https://wp.xxx.org/wp-admin/post-new.php' cannot be created in a document with origin 'https://site3.wp.xxx.org' and URL 'https://site3.wp.xxx.org/wp-admin/post-new.php'.

karpikpl commented 1 year ago

the subdomain part worked after adding this to wp-config.php

/** overriding HTTP_HOST header */
if (!empty(getenv('AFD_DOMAIN'))) {
        $_SERVER['HTTP_HOST'] = getenv('AFD_DOMAIN');
}

if (array_key_exists('HTTP_X_FORWARDED_HOST', $_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_HOST'])){
        $_SERVER['HTTP_HOST']=$_SERVER['HTTP_X_FORWARDED_HOST'];
}