0
votes

I have a Wordpress site hosted in an Azure Web App. It works fine when accessed directly by the web app. But when I put it behind the Azure Application Gateway, I receive "Too_Many_Redirects" error.

I have another website behind the Application Gateway, that is not a Wordpress, and this does not occur.

Has anyone ever experienced this? It's there any specific setting or workaround to make this work?

Edit 1----

Application Gateway Configs:

  • Health Probe Health Probe settings

    • HTTP Settings HTTP settings

    • Listener Listener settings

    • Backend Pool Backend Pool settings

    • Rule Rule settings

The Web App endpoint is in HTTPS.

Edit 2----

  • Backend Health Backend Health

Today I made a lot of tests and find a way to make this work, but doesn't solve the problem, instead, creates another one. In Wordpress at 'SiteURL' and 'Home' settings instead of use the desired address, the custom one, I used the default address provided by Azure Web App . Doing like that, the TOO_MANY_REDIRECTS error was gone, but the links of my website changed to *.azurewebsites.net, which is a big problem.

I tried the 'Home' address with HTTPS and HTTP. No success.

I just discovered that even with no SSL, the problem occurs. Only works with the 'azurewebsites' address, that break my links.

3
Could you share the configuration of your rules on Application Gateway ? And what is the Web App endpoint (HTTP or HTTPS) ? - Ivan Ignatiev
@IvanIgnatiev-MSFT I updated my question with Application Gateway settings and the Web App endpoint type. - fds13

3 Answers

1
votes

You can turn off Wordpress's redirects by putting

remove_action('template_redirect', 'redirect_canonical');

at the end of the wp_config.php file. For me on Ubuntu 18.04 it was in /var/www/wordpress.

I had a similar issue. Bear in mind, I'm very new to developing. I had to provision a Ubuntu 18.04 virtual machine(VM) in Azure with wordpress. I needed to use an App Gateway to route traffic coming from the machine. I am using Azure App Gateway v2. My custom domain name is pointing to the app gateway's public IP. In the Ubuntu VM I installed Apache and in the apache config file I put DocumentRoot /var/www/wordpress and all the other settings for https connection. However, with this setup Wordpress was redirecting me to the private IP so the user started having their url turn from www.XXXXX.com to 10.X.X.X. Then I tried switching the hostname in wordpress to www.XXXXXX.com but that made the site completely unresponsive. At the end I used that line to disable Wordpress's redirects and now it works as it should. I was probably designing it incorrectly so consider other solutions first.
edit: some typos

0
votes
  1. Make sure you don't have any sort of additional redirection that is set from the Application gateway.

  2. You can take a fiddler trace and see who is throwing the 301.

  3. Make sure you have the redirection and authentication turned off on the WebApp

  4. You might have redirection set on the Wordpress site, just have a look at it once.

I am pretty sure it's the WebApp and not the Application gateway.

0
votes

I finally solved this question! There are two main problems in my initial configuration.

  1. Is needed to use HTTPS in the whole process, end-to-end. So, I have to use the HTTPS protocol in the HTTP setting configuration. Using HTTPS in HTTP setting require a Health Probe with HTTPS protocol as well.

  2. The Backend pool can't point to the 'App Services' option. Instead, I used the 'IP address or FQDN' and put the website address in the name field. When I point to the 'App Service' option and select the corresponding Web App, It tries to reach the web app by the default address (*.azurewebsites.net), what causes the Wordpress to redirect it to the custom address, that hits the Application Gateway again and so on.

After modifying these two (three) options, is needed to reconfigure the Rule settings too.

Doing like that I don't needed to change anything in my Web App or Wordpress configurations.