I recently started hosting some WordPress sites on Azure as App Service sites. I wanted to put them behind an Azure Front Door to create a fast and secure experience. However after setting up the Front Door the WordPress site got stuck in a redirect loop, eventually timing out with the error
ERR_TOO_MANY_REDIRECTS – <domain> redirected you too many times
Firefox would show this as “The page isn’t redirecting properly”
I had misconfigured the URLs on the Front Door and on the App Service site. When you host a WordPress site behind a Front Door there the are a few URLs at play. A misconfiguration can easily cause a redirection loop. If WordPress detects traffic coming into a URL that is different to what is set under Settings => General it will redirect to it.
I was not setting the host header on the Front Doors back end pool, and I had not added the front end domain as a custom domain on the App Service site.
In addition there is a known tweak that generally needs to be made to WordPress when hosted on Azure using a Linux based App Service site (more on that below).
In this section I will cover how things should be configured.
For the purpose of this example;
- The domain I want people to enter is www.geekshangout.com this is my front end domain name.
- The URL assigned by Microsoft for my App Service site is geekshangout.azurewebsites.net this is where by back end pool will point.
How it should look
A normal flow should look like this.
Front Door Setup
- Your Front Door should have the domain you want visitors to use as a front end domain.
- For each of the backends in you back end pool the “Backend host header” should be setup as your front end domain name not your app service domain name. For example;
App Service Site Setup
Your App Service site will need a custom domain for your front end domain name, www.geekshangout.com in my example. However you will hit an issue when you try and add the custom domain. Azure will want you point the domain to the App Service Site to validate it, however this would break you Front Door setup.
Instead you can add a CNAME for the domain
Alias: App Service domain name
Note: if you front end domain is using a CNAME other than www put that after awverify. instead of www
You will now be able to add the front end domain as a custom domain on the App Service site without affecting the DNS routing to your Front Door.
Under Setting => General the WordPress URL and Site URL should be set as your front end domain name.
I also had to modify my wp-config.php file to add the following block of code to the top
// Fix HTTPS Redirect if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on'; else $_SERVER['HTTPS']='off';
WordPress Emails and Azure
If you will need to send emails from your WordPress site when hosted on Azure, take a look at this post WordPress Emails on Azure Configuring SendGrid